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: example.com/blog

site config looks as follows:

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

        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 example.com/blog, 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/example.com/html/staat/index.php"

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/example.com/html/staat/index.php. I suspect this is the reason for the 404. Because the index.php does not exist at /var/www/example.com/html/staat/index.php.

Update 2:

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


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.

  • How would "You can either add the alias directive to the location block" look like? – beta Apr 2 '18 at 20:50
  • You can just copy and paste it. – Michael Hampton Apr 2 '18 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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