PHP Apps In A Subdirectory In Nginx
By T. H. Wright
Published:
Last Updated:
I needed a way to install a PHP app (e.g., WordPress) into a subdirectory and I kept hitting a brick wall. I couldn’t make heads or tails of what I was missing. This quick tutorial solved my problems. Hopefully it helps someone else!
https://serversforhackers.com/c/nginx-php-in-subdirectory
TL;DR, TL;DW
location /nested { alias /var/www/nested/public; try_files $uri $uri/ @nested;
location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } }
location @nested { rewrite /nested/(.*)$ /nested/index.php?/$1 last; }