Skip to content

Instantly share code, notes, and snippets.

@priatmoko
Last active December 26, 2018 06:21
Show Gist options
  • Save priatmoko/4c18622599c680322b2dc0f9ad4d6c8e to your computer and use it in GitHub Desktop.
Save priatmoko/4c18622599c680322b2dc0f9ad4d6c8e to your computer and use it in GitHub Desktop.
NginX Configuration for removing public and index, laravel in sub directory
#The are a lot of methods to separate configuration of laravel in nginx. It is only one of them but not the best.
#Configuration for removing public and index in laravel or lumen that run on nginX
#This configuration implemented in ubuntu server
#We can copy this code directly to "/etc/nginx/site-enabled/default"
#or you can separate this file, to reduce complexity / large code in file "/etc/nginx/site-enabled/default"
#directory name
location /dir {
#we point the alias to the lavel public directory
#project root
alias /var/www/dir/public;
#calling the location defined below
try_files $uri $uri/ @dir_location;
#PHP configuration
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
}
#define location
location @dir_location {
rewrite /dir/(.*)$ /dir/index.php?/$1 last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment