nginx + wordpress in subfolder + debian configuration

beta asked:

In a subfolder on a domain I want to install a wordpress blog. I use nginx. The URL to access the blog should be like this:

site config looks as follows:

server {
        listen 80;
        listen [::]:80;
        root /var/www/; 
        index index.php index.html index.htm index.nginx-debian.html;   

        location /blog {
                alias /var/www/example.comblog/html;
                index index.php;
                try_files $uri $uri/ /blog/index.php?q=$uri&$args;

        location ~ /blog/.+\.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

        location ~ /\.ht {
                deny all;
  • The wordpress files reside in the folder
    /var/www/example.comblog/html. When accessing,
    the browser shows a 404 error.

  • In /etc/php5/fpm/php.ini I adapted this: cgi.fix_pathinfo=0

  • nginx version: nginx/1.6.2

  • /var/log/nginx/error.log does not show anything of interest


After setting error logging to debug, (among others) the following lines appear. Maybe this helps:

open index "/var/www/example.comblog/html/index.php"
internal redirect: "/blog/index.php?"
rewrite phase: 1
test location: "/blog"
test location: ~ "/blog/.+\.php$"
using configuration "/blog/.+\.php$"
http script var: "/blog/index.php"
trying to use file: "/blog/index.php" "/var/www/"

The internal redirect seems incorrect? And in the last line there should be /var/www/example.comblog/html/staat/index.php instead of /var/www/ I suspect this is the reason for the 404. Because the index.php does not exist at /var/www/

Update 2:

Okay there seems to be a long standing issue with using alias together with try_files.

My answer:

You are not running into the long standing issue with using alias with try_files.

You simply aren’t using alias at all in the appropriate location. Thus the document root is inherited from the level above.

You can either add the alias directive to the location block, or make it a nested location as in the answer you linked to.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.