how to prevent Nginx to redirect location to a configured proxy_pass url and port number

5.6k Views Asked by At

Hi guys i am having a problem with nginx, i have configure phpmyadmin to run with nginx phpmyadmin is configured to run on port 8080. I access phpmyadmin via localhost/phpmyadmin and it give me the proper login screen below.

phpmyadmin login screen

after login the url on the address bar changes to the configure port from localhost/phpmyadmin to localhost:8080/phpmyadmin and it throws

error message

here is my nginx configuration:

server{
    listen 443 ssl;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_certificate /etc/certificate/live/localhost/permission.pem;
    ssl_certificate_key /etc/certificate/live/localhost/privkey.pem;
    include /etc/certificate/live/localhost/ssl-nginx.conf;

    access_log /var/log/nginx/apache2-access.log;
    error_log /var/log/nginx/apache2-error.log;

location /phpmyadmin{
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header Host $http_host;
        proxy_set_header X-Ssl on;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080/phpmyadmin;
        proxy_redirect off;
    }

}

Thanks in advance.

1

There are 1 best solutions below

0
On

You should not be using proxy_redirect off;. You want to change the redirects

location /phpmyadmin{
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header Host $http_host;
        proxy_set_header X-Ssl on;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080/phpmyadmin;
        proxy_redirect http://127.0.0.1:8080/ $scheme://$host/;
        proxy_redirect http://localhost:8080/ $scheme://$host/;
        proxy_cookie_domain 127.0.0.1 $host;
        proxy_cookie_domain localhost $host;
    }

And you also want to setup the cookie so login works