Nginx reports 403 code when using Laravel framework

Posted August 8, 2014 39.3k views


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?


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.

Submit an Answer
1 answer

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?