AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 497456
Accepted
F21
F21
Asked: 2013-04-09 16:39:03 +0800 CST2013-04-09 16:39:03 +0800 CST 2013-04-09 16:39:03 +0800 CST

为什么nginx在请求为HEAD时不发送Content-Length头?

  • 772

我正在使用 CURL 测试对我的 nginx 服务器的 HEAD 请求。提供的文件是一个简单的PHP文件。

如果我使用GET:

$ curl -XGET http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 00:35:35 GMT
Content-Type: text/html
Connection: keep-alive
Content-Length: 72080

但是,如果我使用HEAD:

$ curl -XHEAD http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 00:37:00 GMT
Content-Type: text/html
Connection: keep-alive

为什么如果请求是HEAD,nginx 会省略Content-Length标头?php 脚本非常简单,不会以HEAD任何特殊方式响应。

我可以在 nginx 中打开任何选项,以便它也发送Content-LengthforHEAD吗?

相关nginx信息:

nginx version: nginx/1.2.8
built by gcc 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.2.8 --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre --conf-path=/etc/nginx/nginx.conf --add-module=../headers-more-nginx-module-0.19rc1

配置:

user  www-user;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include mime.types;
    default_type  application/octet-stream;
    client_max_body_size 10M;

    sendfile        on;
    keepalive_timeout  65;

    more_clear_headers "Server";

    gzip  on;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml;

    server {
        server_name test.com;
        root   /www;
        index index.php index.html index.htm;

        listen       80  default_server;

        rewrite ^/(.*)/$ /$1 permanent; #remove trailing slash

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        include      general/*.conf;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {

    fastcgi_intercept_errors on;

    fastcgi_pass   unix:/run/php/php-fpm.sock;

    fastcgi_index index.php;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    include        fastcgi_params;

        }
    }
}
nginx
  • 1 1 个回答
  • 5843 Views

1 个回答

  • Voted
  1. Best Answer
    Castaglia
    2016-02-16T13:54:41+08:002016-02-16T13:54:41+08:00

    nginx可能不包含Content-LengthHTTP 请求的响应标头的一个原因HEAD是,根据定义,对HEAD请求的响应不得在响应中包含消息正文(有关详细信息,请参阅RFC 2616 )。

    现在,HTTP 服务器可以发送请求Content-Length: 0响应HEAD,但这是不一定需要的附加信息。那么,我怀疑这只是通过在对您的请求的响应中nginx不包含标头来省略原本冗余的响应标头。Content-LengthHEAD

    希望这可以帮助!

    • 2

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve