I would like to be able to support HEAD requests. For the most part, HEAD works well with static files. However, if I am trying to use a HEAD request against a PHP file, it is missing the Content-Length or the Transfer-Encoding header.
PHP-FPM is connected to nginx 1.2.8 using FCGI. I also have gzip enabled.
user www-user;
worker_processes 1;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10M;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript;
server {
server_name test.com;
root /web;
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;
}
listen 80 default_server;
error_page 500 502 503 504 /50x.html;
}
}
If I use a GET, everything works as expected:
$ curl -XGET http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 06:58:50 GMT
Content-Type: text/html
Transfer-Encoding: chunked <-------------------
Connection: keep-alive
But, if I use a HEAD, Transfer-Encoding is missing:
$ curl -XHEAD http://test.com/phpinfo.php -I
HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 06:59:24 GMT
Content-Type: text/html
Connection: keep-alive
What's the reason for nginx not including the Transfer-Encoding header? Is there anyway to turn it on? Interestingly, if I try and set the Transfer-Encoding header inside the PHP script, it is still removed by nginx.