问题
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.
My nginx.conf is this:
# 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;
}
}
}
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
My php-fpm is running. I can use ps -ef | grep php-fpm to check. there are multi processes at there.
my index.php is just a phpinfo():
index.php:
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);
echo phpinfo();
?>
EDIT-1
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
Thanks Dan, I changed the fastcgi_pass 127.0.0.1:9000 to:
fastcgi_pass unix:/tmp/php-cgi.sock;
But I get the File not found. error, when I access the index.php.
回答1:
You specify a unix socket for fpm to listen:
listen = /tmp/php-cgi.sock
But in nginx you specify an IP address:
fastcgi_pass 127.0.0.1:9000;
Configure either IP only or Unix Socket only:
fastcgi_pass unix:/tmp/php-cgi.sock;
or
listen = 127.0.0.1:9000
Concerning your edit 2:
Try adding this param:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
And also your SCRIPT_FILENAME does not look correct, the folder you specify most probably does not exist (/scripts).
Try this dynamic path:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
回答2:
You should use the bellow configurations of php in nginx:
location ~ \.php$ {
root html;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
The $document_root$fastcgi_script_name statement is invalid now.
来源:https://stackoverflow.com/questions/51020731/nginx-php-an-error-occurred-sorry-the-page-you-are-looking-for-is-currently