Nginx

Nginx 反向代理到 PHPMyAdmin 返回 404

  • September 20, 2018

在我的網路上,我有兩台伺服器:

  • 一台代理伺服器 (ip: 192.168.1.10) 使用 nginx 來處理所有傳入的 HTTP 請求。
  • 192.168.1.33一台執行 Apache2 和 PHPMyAdmin的網路伺服器 (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
}

db.conf:

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.php404 說

在此伺服器上未找到請求的 URL /phpmyadmin/phpmyadmin/index.php。

我怎樣才能讓通過登錄成為可能db.example.com

$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'] = '/';

引用自:https://serverfault.com/questions/931849