0

On my network I have two servers:

  • One proxy-server (ip: 192.168.1.10) using nginx to handle all incoming HTTP requests.
  • One web-server (ip: 192.168.1.33) running Apache2 and PHPMyAdmin

I want the proxy server to handle certain requests like this:

  • www.example.com - leads to the Apache2 web-server
  • db.example.com - leads to the PHPMyAdmin login-page

I have tried to configure nginx to do this by creating the following .conf-files in /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
}

Right now when I use db.example.com I get directed to the PHPMyAdmin login-page. However, the problem is that once I log in, the URL changes to db.example.com/phpmyadmin/index.php and it gives a 404 saying

The requested URL /phpmyadmin/phpmyadmin/index.php was not found on this server.

How can I make it possible to login through db.example.com?

Patrick Mevzek
  • 9,921
  • 7
  • 32
  • 43
oleter
  • 3
  • 1
  • 4

2 Answers2

0

Set $cfg['PmaAbsoluteUri'] in your phpMyAdmins config.inc.php:

Sets here the complete URL (with full path) to your phpMyAdmin installation’s directory. E.g. https://www.example.net/path_to_your_phpMyAdmin_directory/. Note also that the URL on most of web servers are case sensitive (even on Windows). Don’t forget the trailing slash at the end.

Starting with version 2.3.0, it is advisable to try leaving this blank. In most cases phpMyAdmin automatically detects the proper setting. Users of port forwarding or complex reverse proxy setup might need to set this.

(highlighting by me)

Setting this to / should do it.

$cfg['PmaAbsoluteUri'] = '/';
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
0

on the apache make sure that you made a virtual host db.domain.com which ponints to /var/www/html/phpmyadmin and on .db conf

server {

  server_name db.domain.com;

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