root /var/www/html;
location /site2/ {
alias /srv/www/project2/;
}
on request of /site2/top.gif
, the file /srv/www/project2/top.gif
will be sent.
According to Nginx Alias above, you could define PHP location in that with SCRIPT_FILENAME
setting for Subdirectory path.
location /site2/ {
alias /srv/www/project2/;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# Apply the subdirectory base path to PHP script
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
If you need pretty URL such as Laravel PHP framework, you could seriously setup try_files with trick:
location /site2/ {
alias /srv/www/project2/;
# Pretty URI trick
try_files $uri $uri/ /site2//site2/index.php?$query_string;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# Apply the subdirectory base path to PHP script
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}