All Laravel routes "not found" on nginx

July 17, 2015 9.9k views
Nginx PHP Frameworks Deployment DigitalOcean PHP Ubuntu

Hello, when I try to access my test app, just the index route works:
malte.italoborg.es

If I try to access another route, like:
malte.italoborg.es/admin

I got 404 error.

My nginx app file:

server {
    listen 80;
    server_name malte.italoborg.es;
    root /home/italo/www/malte.italoborg.es/public;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /home/log/nginx/malte.italoborg.es-error.log error;
    error_page 404 /index.php;
    sendfile off;

    # Point index to the Laravel front controller.
    index index.php;

    location / {
            try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        #deny all;
    }
}
1 comment
  • Try this:

    
    #location / {
                try_files $uri $uri/ /index.php;
    #    }
    
        location ~ \.php$ {
            #try_files $uri /index.php =404;
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
1 Answer

This question was answered by @ggeduvn:

Try this:


#location / {
           try_files $uri $uri/ /index.php;
#    }

   location ~ \.php$ {
       #try_files $uri /index.php =404;
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
   }

View the original comment

Have another answer? Share your knowledge.