Nginx、PHP - 发生错误.抱歉,您要查找的页面当前不可用.请稍后再试 [英] Nginx, PHP - An error occurred. Sorry, the page you are looking for is currently unavailable. Please try again later
问题描述
当我访问我的 /usr/local/nginx-1.12.2/html
的 index.php
时出现错误.
I get an error when I access my index.php
of my /usr/local/nginx-1.12.2/html
.
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
配置是这样的:
in my /usr/local/php-7.1.16/etc
, the php-fpm.conf
config is this:
# 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
进行检查.那里有多个进程.
My php-fpm
is running. I can use ps -ef | grep php-fpm
to check. there are multi processes at there.
我的 index.php
只是一个 phpinfo()
:
index.php
:
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);
echo phpinfo();
?>
<小时>
EDIT-1
在我的 nginx 的 error.log
中:
In my nginx's 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
谢谢丹,我把 fastcgi_pass 127.0.0.1:9000
改成:
Thanks Dan, I changed the fastcgi_pass 127.0.0.1:9000
to:
fastcgi_pass unix:/tmp/php-cgi.sock;
但是当我访问 index.php
时,出现 File not found.
错误.
But I get the File not found.
error, when I access the index.php
.
推荐答案
你指定一个 unix socket 供 fpm 监听:
You specify a unix socket for fpm to listen:
listen = /tmp/php-cgi.sock
但是在 nginx 中你指定了一个 IP 地址:
But in nginx you specify an IP address:
fastcgi_pass 127.0.0.1:9000;
<小时>
仅配置 IP 或仅 Unix 套接字:
Configure either IP only or Unix Socket only:
fastcgi_pass unix:/tmp/php-cgi.sock;
或
listen = 127.0.0.1:9000
<小时>
关于您的编辑 2:
尝试添加此参数:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
而且您的 SCRIPT_FILENAME
看起来也不正确,您指定的文件夹很可能不存在 (/scripts
).
And also your SCRIPT_FILENAME
does not look correct, the folder you specify most probably does not exist (/scripts
).
试试这个动态路径:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
这篇关于Nginx、PHP - 发生错误.抱歉,您要查找的页面当前不可用.请稍后再试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!