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-serverdb.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
?