amazon-web-services - 从响应中删除 AWS/EC2 状态文本

标签 amazon-web-services http amazon-ec2 http-headers

我的应用程序部署在 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.

https://http2.github.io/http2-spec/#HttpSequence

关于amazon-web-services - 从响应中删除 AWS/EC2 状态文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49372106/

相关文章:

javascript - CORS 放置 : Not found with jQuery. ajax

http - 在 Indy POST 之后访问 JSON 数据

r - 在 Amazon 上使用 R 的 GPU 包

amazon-web-services - Amazon Lightsail 比 EC2 便宜多少?

使用 ECDSA 对 Amazon AWS EC2 服务器进行 SSH 指纹验证?

amazon-web-services - AWS Elasticache -- 如何从控制台刷新节点?

c# - 异步 Amazon S3 分段上传的进度信息和部件号

http - 为用户与其他实体交互构建 URL 的 RESTful 方式是什么?

python - Django、Heroku 和 Amazon 入门

sql - 从 athena aws 中单独字段中的整数创建日期