5

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

UPDATE 1:

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/blog/index.php"

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

Update 2:

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

beta
  • 5,324
  • 15
  • 57
  • 99
  • Your php location needs to be nested into the aliased location - see [my answer here](https://stackoverflow.com/questions/43067331/how-to-run-django-and-wordpress-using-nginx-and-gunicorn-at-the-same-domain/43067793#43067793). – Richard Smith Apr 03 '18 at 08:49

0 Answers0