It's easy to configurate a Laravel server site with directory protection:
Laravel Web Server Configuration
Laravel smartly detects the current base url so that you don't need to set the base url for subdirectoy:
// All Url path would return full URL with current path
url('/');
url('');
With same path included /public
, for example: /sublara/
##
# Subdirectory Laravel Application Configuration
##
# App directories protection
location /sublara/ {
return 403;
}
# Laravel public
location /sublara/public/ {
try_files $uri $uri/ /sublara/public/index.php?$query_string;
}
After above setting:
- Access Laravel web:
//hostname/sublara/public/
- Protect Laravel app directories:
//hostname/sublara/
(/sublara/composer.json
)
Using alias
to implement different subdiretory pointed to specified project path:
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;
}
}