[英]Make Nginx ignore the content-length header from PHP-FPM
我有PHP FPM + Nginx設置。 我的一個PHP應用程序設置了一個無效的內容長度標頭,因此我試圖使用fastcgi_hide_header忽略它,但是它不起作用。 它適用於Content-Length以外的標頭,因此我特別認為存在問題。
正確的做法是什么? 我無法修改PHP應用程序以解決問題的根源。
server {
listen 8000 default_server;
root /var/www;
index index.php index.html index.htm;
rewrite_log on;
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ /index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_hide_header X-Fake-Header;
fastcgi_hide_header Content-Length;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
如果刪除PHP中設置標頭的代碼,則輸出(這是所需的輸出):
< HTTP/1.1 200 OK
* Server nginx/1.4.1 (Ubuntu) is not blacklisted
< Server: nginx/1.4.1 (Ubuntu)
< Date: Thu, 13 Feb 2014 01:58:07 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.5.3-1ubuntu2.1
如果我保留代碼,但使用上面的nginx配置,則會得到以下信息:
< HTTP/1.1 200 OK
* Server nginx/1.4.1 (Ubuntu) is not blacklisted
< Server: nginx/1.4.1 (Ubuntu)
< Date: Thu, 13 Feb 2014 01:59:09 GMT
< Content-Type: text/html
< Content-Length: 6
< Connection: keep-alive
< X-Powered-By: PHP/5.5.3-1ubuntu2.1
我最終不得不在Nginx中使用HttpHeadersMore模塊 (如果您在Ubuntu上,則它包含在nginx-extras
但不包含在nginx-full
)。
安裝模塊后,我將以下內容添加到我的Nginx配置中:
more_clear_headers Content-Length;
這按預期工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.