Nginx 反向代理到 PHPMyAdmin 返回 404

Nginx 反向代理到 PHPMyAdmin 返回 404

我的网络上有两台服务器:

  • 一个代理服务器(ip:)192.168.1.10使用 nginx 来处理所有传入的 HTTP 请求。
  • 192.168.1.33一个运行 Apache2 和 PHPMyAdmin 的Web 服务器(ip: )

我希望代理服务器处理某些如下请求:

  • www.example.com- 指向 Apache2 网络服务器
  • db.example.com- 进入 PHPMyAdmin 登录页面

我尝试通过创建以下 .conf 文件来配置 nginx 来执行此操作/etc/nginx/conf.d/

www.conf:

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

  server_name www.example.com;

  location / {
    proxy_pass http://192.168.1.33/;
  }

  listen [::]:443 ssl ipv6only=on; # managed by Certbot
  listen 443 ssl; # managed by Certbot
  ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

数据库配置文件:

server {

  server_name db.example.com;

  location / {
    proxy_pass https://192.168.1.33/phpmyadmin/;
    proxy_redirect off;
    proxy_set_header Host $host;
  }
  listen [::]:443 ssl; # managed by Certbot
  listen 443 ssl; # managed by Certbot
  ssl_certificate /etc/letsencrypt/live/db.example.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/db.example.com/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
  if ($host = db.example.com) {
    return 301 https://$host$request_uri;
  } # managed by Certbot

  listen 80;
  listen [::]:80;

  server_name db.example.com;
    return 404; # managed by Certbot
}

现在当我使用时,db.example.com我会被引导到 PHPMyAdmin 登录页面。然而,问题是,一旦我登录,URL 就会变成,db.example.com/phpmyadmin/index.php并显示 404 错误

该服务器上未找到请求的 URL /phpmyadmin/phpmyadmin/index.php。

我怎样才能成功登录db.example.com

答案1

$cfg['PmaAbsoluteUri']在您的 phpMyAdmins config.inc.php 中:

在此设置 phpMyAdmin 安装目录的完整 URL(带完整路径)。例如https://www.example.net/path_to_your_phpMyAdmin_directory/。还请注意,大多数 Web 服务器上的 URL 区分大小写(即使在 Windows 上也是如此)。不要忘记末尾的斜杠。

从 2.3.0 版开始,建议尝试将其留空。大多数情况下,phpMyAdmin 会自动检测正确的设置。端口转发或复杂反向代理设置的用户可能需要设置此项

(我突出显示)

将其设置为/就可以了。

$cfg['PmaAbsoluteUri'] = '/';

答案2

在 apache 上,确保您创建了一个虚拟主机 db.domain.com,它指向/var/www/html/phpmyadmin .db conf

server {

  server_name db.domain.com;

  location / {
    proxy_pass https://192.168.1.33/;
    proxy_redirect off;
    proxy_set_header Host $host;
  }

相关内容