Report this

What is the reason for this report?

Nginx reports 403 code when using Laravel framework

Posted on August 8, 2014

Hi,

I just installed my first droplet (LEMP) thanks to some information on DO tutorials. But I’m having a problem and I dont know what is the cause (or fix :) ) for the issue.

I created a new file in ‘sites-available’ with the following server block;

 server {
 
	server_name ~^(.+)\.dev\.mydomain\.nl$;
	set $file_path $1;
	
	root /home/dev-mydomain-nl/$file_path/public/;
	index index.php;
	
	location / {
		try_files $uri $uri/ /index.php?$query_string;
	}
	


	# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
	location ~ \.php$ {
			try_files $uri /index.php =404;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include fastcgi_params;
	}
	
}

As you can see, I created a wildcard subdomain which also has a variable root directory. I also installed the Laravel framework. When I visit a domain, I see Laravels default page. But as soon as I browser to an page (for example …nl/test/) I get the 403 - Forbidden page.

The error in the log file also states:

directory index of "/home/dev-mydomain-nl/mike/public/test/" is forbidden

What should happen, is that all trafic is routed to the index file (unless the file itself exists). But what should I change in the Nginx config?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The test directory does not exists. All traffic should be routed via the index.php file in the public directory (unless the requested file exists, like an image, CSS or js file of course :)).

But what should I change in the try_files?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.