Rumah >pembangunan bahagian belakang >tutorial php >nginx和php-fpm之间是怎样通信的?
<code>server { root /srv/www; location / { index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name; include fastcgi_params; } } </code>
在目录/srv/www中有index.html index.php 两个文件,访问localhost/index.html ,localhost 能够正常显示/srv/www/index.html页面的内容,但是访问index.php文件却显示File Not Found,不知到是怎么回事?在这种情况下难道nginx不是应该将/srv/www/index.php文件先传送给监听在127.0.0.1:9000的php解析器,然后通过其解析后返回解析器的内容给客户端吗?不知到哪里的问题,希望帮忙解答下
<code>server { root /srv/www; location / { index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name; include fastcgi_params; } } </code>
在目录/srv/www中有index.html index.php 两个文件,访问localhost/index.html ,localhost 能够正常显示/srv/www/index.html页面的内容,但是访问index.php文件却显示File Not Found,不知到是怎么回事?在这种情况下难道nginx不是应该将/srv/www/index.php文件先传送给监听在127.0.0.1:9000的php解析器,然后通过其解析后返回解析器的内容给客户端吗?不知到哪里的问题,希望帮忙解答下
估计是你nginx的fpm的配置问题。
我这边这样搞的,已经用过好多个网站了:
<code>server { listen 80; ## listen for ipv4; this line is default and implied root /www/web; index index.html index.htm index.php; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } } </code>
看看fpm错误日志,分分钟定位问题啊!
<code>location / { index index.php index.html index.htm; } </code>
index 中需要加上index.php 优先识别最前面的文件
问题出在这里:
<code>server { root /srv/www;#srv目录 location / { index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /src/www$fastcgi_script_name; #src目录 include fastcgi_params; } } </code>
另外:
下面那部分这样写最好:
<code>location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; # fastcgi_pass unix:/var/run/php5-fpm.sock;#这行和上面一行二选一。 fastcgi_index index.php; include fastcgi_params; } </code>