我在 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 引擎,这意味着正在匹配位置 block 并且正在提供 php 文件,但 php 文件没有被 php block 捕获,所以你的问题出在 php block 中。
在该 block 中,您有 2 个 fastcgi_pass
,一个具有端口 (9000),另一个具有 unix 套接字,您不能同时拥有两者,但由于您已将问题标记为fastcgi 所以我假设你正在使用 fastcgi,尝试评论这一行
#fastcgi_pass unix:/var/run/php5-fpm.sock;
关于nginx - 我的 nginx + fastcgi 配置下载 php 文件而不是执行它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17777774/