Nginx,PHP-发生错误。抱歉,您要查找的页面当前不可用。请稍后再试

时间:2018-06-25 09:57:03

标签: php nginx

访问index.php中的/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的配置是这样的:

# 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;

但是当我访问File not found.时遇到index.php错误。

2 个答案:

答案 0 :(得分:1)

您为fpm指定了一个unix套接字来监听:

listen = /tmp/php-cgi.sock

但是在nginx中,您指定了IP地址:

fastcgi_pass   127.0.0.1:9000;

仅配置IP或仅配置Unix套接字:

fastcgi_pass   unix:/tmp/php-cgi.sock;

listen = 127.0.0.1:9000

关于您的 edit 2

尝试添加此参数:

fastcgi_split_path_info ^(.+\.php)(/.+)$;

您的SCRIPT_FILENAME看起来也不正确,您指定的文件夹很可能不存在(/scripts)。

尝试以下动态路径:

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

答案 1 :(得分:0)

您应该在nginx中使用php的以下配置:

    location ~ \.php$ {
        root           html;
        fastcgi_pass   unix:/tmp/php-cgi.sock;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include        fastcgi_params;
    }

$document_root$fastcgi_script_name语句现在无效。