2

Here is my phpmyadmin config file:

server {
    listen   8080;
    server_name  phpmyadmin;

    access_log  /var/log/nginx/phpmyadmin.access.log;
    error_log   /var/log/nginx/phpmyadmin.error_log warn;

    root   /var/www/phpmyadmin;
    index  index.php index.htm;

    location ~ \.php {
            include /etc/nginx/fastcgi_params;
            keepalive_timeout 0;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_pass    127.0.0.1:9000;
    }
}

Right now when I go to http://domain.com:8080 it brings up the phpmysdmin site. I want it to only open phpmyadmin if I go to http://domain.com:8080/phpmyadmin. What change do I need to make here?

I have about 4 or 5 apps that I am going to run from nginx, and I'd prefer to keep each one in it's own sites-enabled profile, instead of one big config file that covers them all.

2 Answers 2

3

a little bit more verbose:

server {
  listen       8080;
  server_name  phpmyadmin;

  access_log  /var/log/nginx/phpmyadmin.access.log;
  error_log   /var/log/nginx/phpmyadmin.error_log warn;
  location ~ /phpmyadmin/.*\.php {
    root            /var/www;
    include         /etc/nginx/fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass    127.0.0.1:9000;
  }
  location /phpmyadmin/ {
    root   /var/www;
    index  index.php;
  }
  location = /phpmyadmin {
    rewrite ^ /phpmyadmin/index.php;
  }
  location / {
    return 403;
  }
}

also note the root setting: it's relative to request path, not whatever comes after that. So a request of http://phpmyadmin/phpmyadmin/index.php will make nginx try to find the file in $root/phpmyadmin/index.php where the $root is root path set in the location block.

1
  • Thank you! I've been trying to get this to work all night. I didn't realize it was using the full request path.
    – ABentSpoon
    Jun 25, 2012 at 5:52
2

Use location:

location /phpmyadmin {
        root   /var/www/phpmyadmin;
        include /etc/nginx/fastcgi_params;
        keepalive_timeout 0;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .