在我到处搜索并测试所有内容但仍然无法正常工作之前,当我在浏览器中打开 localhost 时,我安装了 php5-fpm 和 nginx,我看到了这个页面:
欢迎使用 nginx!
所以它现在正在使用 nginx 配置 php5-fpm :
/etc/php5/fpm/pool.d/www.conf
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
所有其他行都已注释,这是 nginx conf:
upstream php {
server unix:/var/run/php5-fpm.socket;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# allow all;
#}
}
问题是当我尝试运行 php 文件时,nginx 将下载 php 文件而不是执行它
PHP-FPM 套接字权限
请检查套接字是否具有适当的权限。
如果输出不同,可能会添加
listen.mode = 0660
到您的。www.conf
可能相关:nginx error connect to php5-fpm.sock failed (13: Permission denied)
nginx 配置
这真的是您的文件所在的位置吗?
这个块应该做什么?
我建议
try_files $uri =404;
从location ~ \.php$
块中删除。为什么 2 和 3 中的行缩进与其余行不同?请注意,这会影响正确的配置,但这给人的印象是它们被粗心地粘贴在一起。请提供指向您使用的说明的链接。
您可以尝试EasyEngine,它可以使用单个命令设置网络服务器
文档/维基:https ://github.com/rtCamp/easyengine/wiki
如何设置:http ://www.unixmen.com/easyengine-auto-installer-script-managing-wordpress-nginx-websites-ubuntu-debian/