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

I have the root of the subdomain point to an offline message: this works.

I want to have /db/ point to phpmyadmin: this doens't work. It says File not found. I tried a bunch of combination of nested locations, root, fastcgi_split_path_info... Can't get it to work. Always says File not found. Any idea why?

Here's my config:

server {
  listen 443 ssl;
  server_name asub.domain.com;

  root    /var/www/sites/offline/public;
  index   index.html index.htm;

  server_tokens off;

  access_log  /var/www/sites/offline/logs/access-secure.log;
  error_log   /var/www/sites/offline/logs/error-secure.log;

  ssl on;
  ssl_certificate /mycert; # this works on other places (I replace with real cert)
  ssl_certificate_key /mycert; # this works on other places (I replace with real cert)

  rewrite_log on;

  location / {
      try_files $uri $uri/ /index.html;

  location /db/ {
      root /usr/share/phpmyadmin;
      try_files $uri $uri/ /index.php;

      location ~ \.php$ {
          fastcgi_pass   phpmain;
          fastcgi_index  index.php;
          fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
          fastcgi_split_path_info ^(/db)(/.*)$;
          include fastcgi_params;
share|improve this question

1 Answer 1

Usually index includes an entry for an index.php file, perhaps you could try:

index   index.html index.htm index.php;

Unless you need the /db/directory for something else, you could delete it and try making a symlink to the phpMyAdmin folder:

ln -s /usr/share/phpmyadmin /var/www/sites/offline/public/db

It is not necessary to enable PHP on the entire root directory unless there is a PHP package you want to run from that directory. I run Ubuntu 12.04, nginx, PHP-FPM, and MariaDB running in Unix sockets, and I find the block below works perfectly, though if you aren't using Unix sockets yours may not work as I have listed, but the location will be more secure.

Just have the location block directly inside the server block:

location ~ /db/.*\.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php5-fpm-sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_param HTTPS on;

To be sure, the message you have that in the subdomain is not something that is identical to something in another subdomain? Under certain conditions nginx will serve from a different server block, so I usually take care to use a unique test file when setting up new server blocks. Also, I find that the command nginx -t run with root privileges reveals many setup errors.

share|improve this answer

Your Answer


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.