Nginx不会将_SERVER 发送到PHP-fpm

这是我的nginxconfiguration文件的一部分:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name; include fastcgi_params; } 

几乎网站加载,因为/的位置也被设置为/ var / www这个configuration文件。

 location / { root /var/www; index index.php index.html index.htm; } 

当我使用phpinfo()并读取PHPvariables表时,我注意到了这一点:

 _SERVER["DOCUMENT_ROOT"] /usr/share/nginx/html 

其他的variables(大部分是在nginx.conf中configuration的)作为服务器名,脚本文件名等被发送到php。 所以,nginx不会把这个variables发送给PHP。 我要做什么?

我使用PHP 5.3.8和nginx 0.8

$ document_root由root指令设置。 “根html” 在php位置中设置$ document_root为<nginx prefix> / html。 看看https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#root-inside-location-block ,看看你应该如何设置你的根在服务器上下文。 它应该看起来像这样:

 server { root /var/www; index index.php index.html index.htm; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

我正在使用nginx 1.0.6,这是在我的fastcgi_params:

 fastcgi_param DOCUMENT_ROOT $document_root; 

不知道这是否会帮助你0.8,但更新nginx将有所帮助,如果没有。