$ _SERVER [“HTTP_ACCEPT_ENCODING”]未由nginx设置

时间:2013-03-22 06:32:49

标签: php apache nginx centos

我在服务器上安装了nginx。现在我没有获得在Apache中工作的$_SERVER["HTTP_ACCEPT_ENCODING"]变量。

如何获得这个?

2 个答案:

答案 0 :(得分:2)

最终通过编辑/etc/nginx/proxy.inc

找到了解决方案

proxy_set_header接受编码“”

proxy_set_header接受编码$ http_accept_encoding

答案 1 :(得分:0)

当您使用NGINX运行PHP-FPM时,php将以完全不同的方式看到$ _SERVER变量(这是因为服务器参数默认传递给nginx中的fcgi脚本)。

这是如何以php-fpm的形式运行php时会看到$ _SERVER变量: 码: 数组([USER] => nobody [HOME] => / [FCGI_ROLE] => RESPONDER [SCRIPT_FILENAME] => /usr/local/www/www.example.com/public_html/example/index.php [ Content-Type] => multipart / form-data [QUERY_STRING] => upload = true [REQUEST_METHOD] => POST [CONTENT_LENGTH] => 40403 [SCRIPT_NAME] => /example/index.php [REQUEST_URI] => /site/index.php?upload=true [DOCUMENT_URI] => /example/index.php [DOCUMENT_ROOT] => /usr/local/www/www.example.com/public_html [SERVER_PROTOCOL] =&gt ; HTTP / 1.1 [GATEWAY_INTERFACE] => CGI / 1.1 [SERVER_SOFTWARE] => nginx / 0.7.65 [REMOTE_ADDR] => 193.110.48.4 [REMOTE_PORT] => 9971 [SERVER_ADDR] => 192.168.1.10 [ SERVER_PORT] => 80 [SERVER_NAME] => www.example.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.example.com [HTTP_ORIGIN] => http://www.example.com [HTTP_X_FILE_SIZE] = > 40403 [HTTP_X_REQUESTED_WITH] => XMLHttpRequest [HTTP_CACHE_CONTROL] => max-age = 0 [HTTP_IF_MODIFIED_SINCE] => Mon,26 Jul 1997 05:00:00 GMT [HTTP _CONTENT_LENGTH] => 40403 [HTTP_X_FILE_NAME] => nokia-6300-yahoo.jpg [HTTP_USER_AGENT] => Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_5_8; zh-CN)AppleWebKit / 533.17.8(KHTML,类似Gecko)版本/ 5.0.1 Safari / 533.17.8 [HTTP_CONTENT_TYPE] => multipart / form-data [HTTP_REFERER] => http://www.example.com/example/index.php [HTTP_ACCEPT] => / [HTTP_ACCEPT_LANGUAGE] => en-us [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_CONNECTION] => keep-alive [PHP_SELF] => /example/index.php [REQUEST_TIME] => 1282822862)

请注意HTTP_CONTENT_TYPE,HTTP_X_FILE_SIZE,HTTP_X_FILE_NAME和其他HTTP_ *变量。

这是一个简单的php函数,它将这些标题值调整为apache,就像那些。

 function getallheaders() {
    $replace_array = array('CONTENT_TYPE' => 'Content-Type',
                    'CONTENT_LENGTH' => 'Content-Length',
                    'X_FILE_SIZE' => 'X-File-Size',
                    'X_FILE_NAME' => 'X-File-Name');
    foreach($_SERVER as $h=>$v) {
        $h = str_replace("HTTP_", "", $h);
        $h = $replace_array[$h];
        $headers[$h] = $v;
    }
    return $headers;

}