nginx 显示 200 ok 状态但不加载页面

nginx 显示 200 ok 状态但不加载页面

我已经在 ubuntu 16.04 服务器上安装了 nginx、php7.0-fpm 和 mysql。一切正常,但是它没有加载 phpmyadmin 的设置页面。下面是我的 phpmyadmin nginx 块。

location /phpmyadmin {
        root /usr/share/;
            index index.php index.html index.htm;
            location ~ ^/phpmyadmin/(.+\.php)$ {
                try_files $uri =404;
                #fastcgi_pass 127.0.0.1:9000;   
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            include fastcgi_params;
            }
    }

以下是我的 nginx 访问日志

/usr/share# tail -f /var/log/nginx/access.log 
127.0.0.1 - - [15/Oct/2016:17:13:06 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:06 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:41 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:44 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:46 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:46 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:47 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:13:47 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:21:26 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
127.0.0.1 - - [15/Oct/2016:17:21:28 +0530] "GET /phpmyadmin/setup/index.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"

我在 nginx 错误日志中没有任何内容。php7.0-fpm 也正常运行,下面是相同的日志摘录。

 tail -f /var/log/php7.0-fpm.log 
[15-Oct-2016 17:09:48] NOTICE: fpm is running, pid 17062
[15-Oct-2016 17:09:48] NOTICE: ready to handle connections
[15-Oct-2016 17:09:48] NOTICE: systemd monitor interval set to 10000ms
[15-Oct-2016 17:21:10] NOTICE: Terminating ...
[15-Oct-2016 17:21:10] NOTICE: exiting, bye-bye!
[15-Oct-2016 17:21:11] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[15-Oct-2016 17:21:11] NOTICE: fpm is running, pid 17297
[15-Oct-2016 17:21:11] NOTICE: ready to handle connections
[15-Oct-2016 17:21:11] NOTICE: systemd monitor interval set to 10000ms

我需要专家的建议,因为我尝试将 php-fpm 监听模式从本地主机端口 9000 更改为 php.sock。在 phpmyadmin nginx 块配置中也可以观察到同样的情况。

答案1

除了 phpmyadmin 附加内容之外,通常您的/etc/nginx/sites-available/default文件应如下所示,以便处理 PHP:

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
  include snippets/fastcgi-php.conf;

  # With php-fpm (or other unix sockets):
  fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
  }

.php因此,当您在浏览器中打开文件时,此位置指令将处理.php包括该文件在内的文件fastcgi-php.conf,并将 php 脚本传递给 php7.0-fpm。

对任何 Nginx 配置文件进行任何更改后,立即测试配置文件,如下所示sudo nginx -t,如果一切正常,您应该看到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

然后输入sudo service nginx reload

ghi.php您可以通过添加包含此代码片段的文件来测试它:

<?php
phpinfo();
?>

如果你想去cd /var/www/html那里,你可以这样做sudo vim ghi.php

然后你转到你的<server-ip-address>/ghi.php,如果你没有看到任何东西,那么你的服务器仍然没有处理 php。

相关内容