Skip to content

Instantly share code, notes, and snippets.

@ofarukcaki
Last active November 29, 2023 12:00
Show Gist options
  • Save ofarukcaki/f59f6eed6230b65dce326434a25010e0 to your computer and use it in GitHub Desktop.
Save ofarukcaki/f59f6eed6230b65dce326434a25010e0 to your computer and use it in GitHub Desktop.
create-react-app with react-router Nginx 404 error solution in page refresh

You need to edit /etc/nginx/sites/available/default file

change the location part as follows

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

lastly, refresh the Nginx with sudo servuce restart nginx

@MahbbRah
Copy link

MahbbRah commented Jan 5, 2022

Worked perfectly fine for me, Thanks!

@blazsmaster
Copy link

The only code that worked out of many, thanks!

@guhmerces
Copy link

seems it does not work

@nickstuaw
Copy link

Likewise here. This isn't working for me either. Many people online have suggested this.

@lebe-dev
Copy link

lebe-dev commented Nov 29, 2023

It's working. Minimal config:

server {

    listen       80;

    server_name  localhost;

    root   /usr/share/nginx/html;

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment