我在ubuntu 13.04上全新安装php5-fpm和nginx时使用此配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 404 /404.html;
location ~ \.php${
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
但是,我的网页浏览器将php视为文本而不是执行的结果.我应该在哪里寻找解决问题?
最佳答案
您的php代码正在被直接显示,因为它没有被发送到php引擎,这意味着位置块正在匹配并且php文件被提供,但php文件没有被php块捕获,所以你的问题在php块.
在该块中,您有2个fastcgi_pass,一个端口(9000),另一个连接到unix套接字,您不能同时使用,但是由于您已经用fastcgi标记了您的问题,所以我假设您正在使用fastcgi尝试评论这一行
#fastcgi_pass unix:/var/run/php5-fpm.sock;