1

I'm using the following nginx block to route mysite.com/blog to my /var/www/mysite/wordpress/ directory:

location /blog {
    root /var/www/mysite/wordpress;
    rewrite ^/blog/(.+)$ /$1 break;
    try_files $uri $uri/ /blog/index.php?q=$uri&$args;
    index index.php;

    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Everything works fine, except mysite.com/blog/wp-admin/ gives me a 404 error. Visiting mysite.com/blog/wp-admin/index.php works as expected, so it looks like my index rule is not working. What could be the issue here?

0

It's possible to solve this issue using alias directive:

location ^~ /blog {
    alias /var/www/mysite/wordpress;
    index index.php;

    try_files $uri $uri/ /blog/index.php?q=$uri&$args;

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_split_path_info ^(?:\/blog)(.+\.php)(.*);
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

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.