Skip to content
Advertisement

Laravel routes causing 404 Error on live server

I have a laravel app developed on my localhost and working perfectly. I am trying to deploy it onto an AWS Lightsail instance using nginx on Ubuntu 20.04. I have uploaded my laravel app and changed the nginx root directory to laravelapp/public.

The main index page (landing page) is working fine but none of my routes are working (i.e. /login, /about etc). When I try to visit any of the routes I get a 404 not found error.

Here is my nginx/sites_available/default file:

# Default server configuration
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/investa/public;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

}

and this is the view of my route list:

Laravel App Routes

Advertisement

Answer

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

compare here: https://laravel.com/docs/7.x/deployment#nginx

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement