当我访问 /usr/local/nginx-1.12.2/html
的 index.php
时出现错误。
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
我的 nginx.conf
是这样的:
#cat conf/nginx.conf
:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
}
在我的 /usr/local/php-7.1.16/etc
中,php-fpm.conf
配置是这样的:
#cat php-fpm.conf
[global]
pid = /usr/local/php-7.1.16/var/run/php-fpm.pid
error_log = /usr/local/php-7.1.16/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 60
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 60
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
我的 php-fpm
正在运行。我可以使用 ps -ef | grep php-fpm
来检查。那里有多个进程。
我的 index.php
只是一个 phpinfo()
:
index.php
:
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);
echo phpinfo();
?>
EDIT-1
在我的 nginx 的 error.log
中:
2018/06/25 09:36:02 [error] 12360#0: *13338 connect() failed (111: Connection refused) while connecting to upstream, client: 118.113.137.192, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "101.103.23.5"
EDIT-2
谢谢 Dan,我将 fastcgi_pass 127.0.0.1:9000
更改为:
fastcgi_pass unix:/tmp/php-cgi.sock;
但是当我访问 index.php
时,出现 File not found.
错误。
最佳答案
你为 fpm 指定一个 unix 套接字来监听:
listen = /tmp/php-cgi.sock
但是在 nginx 中你指定一个 IP 地址:
fastcgi_pass 127.0.0.1:9000;
仅配置 IP 或仅配置 Unix Socket:
fastcgi_pass unix:/tmp/php-cgi.sock;
或
listen = 127.0.0.1:9000
关于您的编辑 2:
尝试添加这个参数:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
而且您的 SCRIPT_FILENAME
看起来也不正确,您指定的文件夹很可能不存在 (/scripts
)。
试试这个动态路径:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
关于php - Nginx、PHP - 发生错误。抱歉,您要查找的页面目前不可用。请稍后再试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51020731/