Created
November 21, 2025 17:16
-
-
Save mdutt247/b2849a1ecf1fae8a6bc2e4ca19b60f5e to your computer and use it in GitHub Desktop.
A clean, correct, and safe nginx configuration for a Laravel project in a subdirectory using alias.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Host Laravel in sub-directory on Nginx | |
| location = /laravel-app { | |
| return 301 /laravel-app/; | |
| } | |
| location /laravel-app/ { | |
| alias /var/www/laravel-app/public/; | |
| try_files $uri $uri/ @laravelproject; | |
| } | |
| location ~ ^/laravel-app/(.*\.php)$ { | |
| include fastcgi_params; | |
| fastcgi_param SCRIPT_FILENAME /var/www/laravel-app/public/$1; | |
| fastcgi_pass php_workers; | |
| # or | |
| # fastcgi_pass unix:/run/php/php8.4-fpm.sock; | |
| } | |
| location @laravelproject { | |
| rewrite /laravel-app/(.*)$ /laravel-app/index.php?/$1 last; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment