Running PHPmyAdmin on Nginx, port 8080 passed to varnish not working well!

I installed Nginx, Varnish and PHP-fpm. Then I installed PHPmyAdmin and made a virtual host for it:

server{
    listen 8080;
    server_name phpmyadmin.Domain.com;
    access_log /var/log/phpmyadmin.access_log;
    error_log /var/log/phpmyadmin.error_log;

    location / {
      root /usr/share/phpmyadmin;
      index index.php;
    }

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
        include         /opt/nginx/conf/fastcgi_params;
    }

}

When I go to phpmyadmin.Domain.com it works as expected! but after submitting username/password it redirects me to phpmyadmin.Domain.com:8080/index.php?... with page cannot be found response as well!

What could I do?


Just came across this same problem myself. The solution is to modify config.inc.php and specify the absolute URL to your phpMyAdmin installation. As per the phpMyAdmin Documentation, add:

$cfg['PmaAbsoluteUri'] = 'http://your.domain.com/path/to/phpmyadmin/';

In this case, it is not necessary to add port_in_redirect off; to the nginx config - although doing does not appear to have any adverse effect (and does help in other scenarios).


Just add the following line in your nginx configuration file, in the php location block anywhere after the include fastcgi_params part:

fastcgi_param   SERVER_PORT 80;

This will tell php that it should not try to redirect to whatever port nginx is listening to, but stay on port 80 as is meant with varnish.