Solution:
I think that the main problem is an inconsistency with your root
directive. Your PHP configuration has WordPress in /var/www/html/blog
whereas your static configuration has WordPress in /var/www/html/blog/blog
.
Assuming that WordPress is installed in the root of /var/www/html/blog
and that the URIs should be prefixed with /blog/
for both real files and permalinks, the correct URI for the entry point should be /blog/index.php
.
The nginx.conf
file should probably be:
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
location /blog {
include /etc/nginx/mime.types;
try_files $uri $uri/ /blog/index.php;
}
If you have a conflicting root
directive within the outer server
container, the above root
directive could be placed inside the two location
blocks unmodified.
I would try /blog/index.php
rather than /blog/index.php?q=$uri&$args
as the last element of try_files
because in my experience, WordPress uses the REQUEST_URI parameter to route permalinks rather than the q
argument as you have implied, but YMMV.
If you do have other applications in this servers root and would like to segregate the WordPress root
more completely, you might nest the PHP location block like this:
location ^~ /blog {
root /var/www/html;
include /etc/nginx/mime.types;
try_files $uri $uri/ /blog/index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}