2014-02-13 34 views
0

我有PHP FPM + Nginx設置。我的一個PHP應用程序設置了一個無效的內容長度標題,所以我試圖用fastcgi_hide_header忽略它,但它不起作用。它適用於Content-Length之外的標題,所以我假設特別有問題。讓Nginx忽略來自PHP-FPM的內容長度標題

這樣做的正確方法是什麼?我無法修改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刪除代碼,設置標題(這是所需的輸出):如果我離開的代碼,但使用上述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:58:07 GMT 
< Content-Type: text/html 
< Transfer-Encoding: chunked 
< Connection: keep-alive 
< X-Powered-By: PHP/5.5.3-1ubuntu2.1 

,我得到這樣的:

< 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 

回答

1

我最後不得不用戶HttpHeadersMore module在Nginx的(如果你在Ubuntu,這是包含在nginx-extras但不nginx-full)。

在安裝模塊,我只是增加了以下我的Nginx的配置:

more_clear_headers Content-Length; 

這和預期一樣。