Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am attempting to use the phpmyadmin package installed via apt on Ubuntu 10.10 with NginX and although I eventually got it to work, I don't think I'm doing it correctly:

server {
  listen   80; ## listen for ipv4

  server_name  vpsnet.dev;

  error_log   /home/robin/dev/vpsnet/error.log;
  access_log  /var/log/nginx/vpsnet.access.log;

  location / {
    root   /home/robin/dev/vpsnet/webroot;
    index  index.php index.html;

    if (-f $request_filename) {
        break;
    }

    if (!-f $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
        break;
    }
  }

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

  location ~ ^/phpmyadmin/.*\.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SERVER_NAME $host;
  }

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/robin/dev/vpsnet/webroot/$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SERVER_NAME $host;
  }
}

The part I'm talking about is this part in particular:

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

  location ~ ^/phpmyadmin/.*\.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SERVER_NAME $host;
  }

If I set the root directive to /usr/share/phpmyadmin and respectively the fastcgi_param SCRIPT_FILENAME to /usr/share/phpmyadmin/$fastcgi_script_name; I get a 404.

I imagine that the server is passing the /phpmyadmin/ part of the URL to the fastcgi server, but I am confused by this, as I come from using Apache and that's not how this kind of thing worked with that.

I'm just wondering if anyone can shed some light on this, why it acts like this, and if I'm doing anything wrong. A "perfect" setup would be great, or at least some information on how to better understand NginX configuration.

share|improve this question
add comment

migrated from superuser.com Apr 7 '11 at 10:56

This question came from our site for computer enthusiasts and power users.

1 Answer

up vote 1 down vote accepted

See if that works:

location /phpmyadmin {
  alias /usr/share/phpmyadmin;
  index index.php index.html;
}

location ~ .php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name;
  include /etc/nginx/fastcgi_params;
  fastcgi_param SERVER_NAME $host;
}

Your config is not wrong or anything. Using root inside location blocks is not advised because if you get a lot of location blocks it starts to get messy (so it's better to have one root per server block) but that's not your case, and the fastcgi settings are usually done on a broader manner (for all php requests).

share|improve this answer
    
Thanks, I would have liked to do a broader fastcgi setting, however I found the $document_root variable wouldn't work. –  Robin Duckett Apr 7 '11 at 11:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.