Laravel in subdirectory – nginx vhost setup

Big credit goes to Hamid Naghipour on stackoverflow for this helpful piece of code https://stackoverflow.com/questions/27785372/config-nginx-for-laravel-in-a-subfolder

Let’s say we have a domain test.sk and we want to install 2 separate laravel installations in subfolders /2018 and 2019/.

Here is a basic setup that works


server {
    listen 80;
    server_name test.sk;	
    root /storage/web/test;


	location /2018 {

		alias /storage/web/test/2018/public;
		try_files $uri $uri/ @nested2018;
	        satisfy any;
	        allow all;
	        index index.php;

		location ~ \.php$ {
	        try_files $uri =404;
	        fastcgi_pass 127.0.0.1:9000;
	        index index.php;
	        fastcgi_index index.php;
	        fastcgi_param SCRIPT_FILENAME $request_filename;
	        include fastcgi_params;
		}
	}

	location @nested2018 {
		rewrite /2018/(.*)$ /2018/index.php?/$1 last;
	}


	location /2019 {

		alias /storage/web/test/2019/public;
		try_files $uri $uri/ @nested2019;
	        satisfy any;
	        allow all;
	        index index.php;

		location ~ \.php$ {
	        try_files $uri =404;
	        fastcgi_pass 127.0.0.1:9000;
	        index index.php;
	        fastcgi_index index.php;
	        fastcgi_param SCRIPT_FILENAME $request_filename;
	        include fastcgi_params;
		}
	}

	location @nested2019 {
		rewrite /2019/(.*)$ /2019/index.php?/$1 last;
	}


    location / {
    	rewrite ^(.*)$ https://$server_name/2018$1 permanent;
    }

}

Write a Comment

Comment