我已经从 amazon ec2 linux 映像配置了 aws 实例,并在服务器上配置了 nginx 和 php。服务器正常提供 html 页面,但不提供 php 页面,并且在浏览器中打开时还显示 503 Bad gateway 错误。
以下是我的 nginx 服务器配置
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include snippets/fastcgi-php.conf;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
我还配置了 php-fpm。以下是从 nginx 错误日志中提取的日志。
2016/07/05 13:11:34 [error] 3969#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 45.117.48.117, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.66.51.131" 2016/07/05 13:11:35 [error] 3969#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 45.117.48.117, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.66.51.131" 2016/07/05 13:11:42 [error] 3969#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 45.117.48.117, server: _, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.66.51.131" 2016/07/05 13:12:18 [error] 3969#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 45.117.48.117, server: _, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "52.66.51.131"
我非常感谢任何关于此的反馈。此外,当我启动 php-fpm 服务时,它显示以下消息
Starting php-fpm-5.6: [05-Jul-2016 13:15:20] WARNING: [pool www] ACL set, listen.owner = 'nginx' is ignored [05-Jul-2016 13:15:20] WARNING: [pool www] ACL set, listen.group = 'nginx' is ignored
[ OK ]
谢谢
答案1
默认的 PHP FPM 监听 Unix 套接字。您已将其注释掉:#fastcgi_pass unix:/var/run/php5-fpm.sock;
如果您想使用套接字,请取消注释 NGINX 配置中的该行以指向正确的套接字。
如果您想按照当前配置通过 IP 连接到 PHP,则需要编辑 php fpm 池设置。(默认为www.conf
)
查找listen
指令并使其listen = 127.0.0.1:9000
替代其默认值。