I'm trying to separate document root of WordPress installations under subdirectories.
Document root of example.com : /var/www/example.com/
Document root of example.com/xyz : /var/www/example.com-xyz/
after a long research, i was able to resolve all the wordpress sites configured like above.
I used below configuration,
root /var/www/example.com/htdocs;
location / {
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
}
location /xyz {
alias /var/www/example.com-xyz/htdocs/;
try_files $uri $uri/ @xyz;
location ~ \.php$ {
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
}
location @xyz {
rewrite ^/xyz(.*) /xyz/index.php?q=$1;
}
This will worked for long. But Problem is that it I couldn't create a page with name starting with above used subdirectory name. Like, http://example.com/xyzzz http://example.com/xyz-something
cannot be made since above request will match subdirectory location block :(
So, I tried location = /xyz { } but I couldnot include
location ~ .php$ { } inside that :( it will throw error like
nginx: [emerg] location "\.php$" cannot be inside the exact location "/xyz"
am I doing the configuration in wrong way ? is there any way to resolve this ?