在 Ubuntu 16.04 上的 Nginx 中设置 phpmyadmin 和反向代理后无法获取 /phpmyadmin

Cannot GET /phpmyadmin after setting up phpmyadmin and reverse proxy in Nginx on Ubuntu 16.04

我遵循了 Digital Ocean 关于设置 Nginx、PHP 和 phpmyadmin 的教程。

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-ubuntu-16-04

但是我仍然无法使用我设置的地址(my-ip-address/phpmyadmin)访问phpmyadmin

并且我为一个 node.js 应用程序设置了反向代理侦听 localhost:8010。

/etc/nginx/sites-available/default 文件中的设置如下:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;
    server_name "my ip address";

    location / {
        proxy_pass http://localhost:8010/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    }

    location ~ /\.ht {
            deny all;
         }

}

您正在使用此块代理对 http://localhost:8010 的所有请求:

location / {
    proxy_pass http://localhost:8010/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

None 的请求可以到达 phpmyadmin。尝试注释掉此块或将其删除,它应该会如您所愿地工作。

您需要一个专为您的location /phpmyadmin准备的区块。由于您设置了一个规则,仅当 location ~ \.php$ { 块上的显式扩展名是 .php 时才重定向到您的 fastCGI,因此 /phpmyadmin 位置将作为对代理应用程序的请求进行处理。您必须添加:

location /phpmyadmin {
   root /path/to/phpmyadmin;
   include snippets/fastcgi-php.conf;
   fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
}

我添加了以下代码来访问 phpmyadmin:

  location /phpmyadmin {
     root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

}