我的应用程序部署在 EC2 实例上的一组 Docker 容器上。在我的本地开发环境中,我使用同一组 docker 容器。我的应用程序发送回 statusText header 以显示有意义的错误消息。在我的本地环境中,所有这些 statusText header 都可以很好地返回响应,但是当将完全相同的代码部署到 AWS 时,statusText header 始终为空,浏览器似乎将其解释为“正常”。我设置的 statusCode 会正确返回。
tl;dr:有谁知道 AWS 或 EC2 上有任何会从响应 header 中删除 statusText 的行为吗?我在文档中找不到任何内容。
这不会返回状态文本:
server {
listen 443 http2 ssl;
server_name api.example.com;
root /var/www/api/public;
error_log /var/log/nginx/api.error.log;
client_max_body_size 16M;
include ssl.conf;
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin '$cors_host';
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers "$http_access_control_request_headers";
add_header Content-Length 0;
add_header Content-Type 'text/plain; charset=utf-8';
return 204;
}
add_header Access-Control-Allow-Origin '$cors_host';
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
include fastcgi_exec.conf;
}
这样做:
server {
listen 80;
server_name api.example.dev;
root /var/www/api/public;
error_log /var/log/nginx/api.error.log;
client_max_body_size 16M;
location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers $http_access_control_request_headers;
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
include fastcgi_exec.conf;
}
最佳答案
HTTP/2 没有保留 HTTP/1.x 中的“原因短语”(状态消息)。
HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.
关于amazon-web-services - 从响应中删除 AWS/EC2 状态文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49372106/