Laravel 5.4 new project nginx redirecting to 404 on every route except index

December 11, 2017 2.5k views

I'm setting up new Laravel 5.4 project on a Ubuntu 16.04.3 x64 nginx machine. The index page works fine but when i try using any other route it takes me to a 404 page. In my development environment, the routes are working fine. I'm guessing it has to do with my server setup.

Below is my information for the server:

server {
        listen 80;
        listen [::]:80;

        root /var/www/;

        index index.php index;


        error_page 404 /404page.php;

        location / {
                try_files $uri $uri/ /$uri.php?$is_args$args;

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        location ~ /\.ht {
                deny all;

    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
Be the first one to answer this question.