Title: Ubuntu 18.04 Laravel 5.7 nginx 1.14 Laravel routes not working
Tags: php;laravel;nginx
Question: I recently moved my server from apache to nginx, when using apache i had a working site using the Laravel framework.  

For some reason no pages other than the base index page just return a 404 error.  I am sure it has something to do with my nginx config.  My currently config is shown below.

```server {
    listen 80;

    server_name munkeemagic.munkeejuice.co.uk;

    root /var/www/html/munkeemagic/mtg-webby/mtg/public;
    index index.php index.html;

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

    location ~* \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
```

I have checked to make sure that all the file permissions are set for user www-data which is the user nginx is using.  I have even tried changing 

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

to

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

but that has not had any impact and i still see the same issue.

So basically with this config if i navigate to http://munkeemagic.munkeejuice.co.uk then the page displays

if i go to http://munkeemagic.munkeejuice.co.uk/login i get a 404 error.

Does anyone have any idea what i may be doing wrong ?

After following user3647971's advice i have modified the config as follows :

```server {
listen 80;

server_name munkeemagic.munkeejuice.co.uk;

root /var/www/html/munkeemagic/mtg-webby/mtg/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.php index.html;

charset utf-8;

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

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

error_page 404 /index.php;

location ~* \.php$ {
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.(?!well-known).* {
    deny all;
}
}
```

I have restarted nginx to take the changes and have also cleared the routes cache, but unfortunately i still have the same problem.

Comment: Um I thought I had, but have just found a default configuration on the laravel website. Will give that a shot and see if that makes a difference.

Comment: unfortunately those two tips did not help.  i have updated my question to reflect that i have changed the config.

Comment: @user3647971 yes that's the path to my public folder in the laravel project

Comment: Yeah, I removed Apache before I installed Ngnix.  Yes the only thing I did was remove Apache and replace it with nginx.

Comment: Yeah, after every config change I made, I restarted nginx.

Comment: Just tried that but it had no impact, still experiencing the same problem.

Comment: Think I will spin up a new VM tomorrow and see if I can get this working locally, if so then I will recreate my live vm

Comment: @user3647971 just to let you know figured out the problem, I still had the default configuration enabled which was overriding my site specific config.  Many thanks for all your help.

Comment: Do you use the default nginx confs that come with laravel?

Comment: Also might wanna clear the routes cache with `php artisan route:cache` :) hope it helps

Comment: Is you root folder of _Laravel_ really what you have defined there? Doesn't seem like laravel standard

Comment: In here: https://stackoverflow.com/questions/39040385/moved-laravel-project-from-apache-to-nginx There's minimal config, and you need to define the root folder to laravels public folder

Comment: Do you still have apache running in the background there? Is the replacing apache with nginx only thing you did?

Comment: did you restart the nginx after trying different configurations?

Comment: `location ~ \.php$` Try this in your .php files section of config

Comment: Okay, let me know how it turns out

Here is the accepted answer: Ok figured out the problem, tbh i was a bit stupid.  My default configuration was overriding my website specific config.  I unlinked the default config restarted nginx and everything started to work correctly.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 16, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:02/10/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><laravel><nginx>', 'Title': 'Ubuntu 18.04 Laravel 5.7 nginx 1.14 Laravel routes not working', 'ViewCount': 808, 'id': 54617703, 'user_AboutMe': '', 'user_AccountId': 13926581.0, 'user_DisplayName': "Mark O'Connor", 'user_Reputation': 11.0, 'user_Views': 3.0, 'user_id': 10055757.0}}