0

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

1 Answer 1

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yep, hit the nail on the head. Don't know why reading the documentation never came into mind but trying to find a solution on Youtube was the first thing that did lol.
Lol been there :) happy coding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.