I have a VM running for development, in this VM I have nginx running on an internal IP (so no hostname) and as such all I can work with is locations rather than separate servers.
The server itself has root /var/www/html;
, one of my locations, /site1
, located in /var/www/html/site1
, has a subdirectory named public
that needs to be used whenever it is accessed. Basically anything going to /site1/(.+)
needs to load /site1/public/$1
instead (except for PHP files)
The issue I'm having is that no matter what setup I try, I cannot get it to not redirect to /var/www/html/site1/public/site1/
, which it does as /site1/
is the current location requested by the browser.
How do I solve this? Is there any way to rewrite without giving Nginx the chance to append the path?
I cannot set the server's root
to /var/www/html/site1/public
, which would fix this issue (that's the setup we have in the live environment), because then the other locations on this development VM stop working.
Relevant config;
root /var/www/html;
location /site1 {
alias /public;
}
location ~* ^/site1/.*\.php$ {
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/site1/application/entry.php;
}