0

I have configured MacOS for nginx and deployed my react js app on it it successfully deployed and running but when i reresh any page it shows 404 not found.

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       8080 default_server;
        server_name  TESTAPP;
        root  /var/www/TESTAPP;
        index index.html index.htm;      
        location / {
            root /var/www/TESTAPP/static;
            index  index.html index.htm;
            try_files $uri /index.html$is_args$args =404;
        }
    }
    include servers/*;
}
9
  • Missing some details. Can u show us the nginx config Commented Jun 2, 2021 at 13:17
  • this should help - stackoverflow.com/questions/43555282/… Commented Jun 2, 2021 at 13:23
  • @Shyam i have also tried but it didn't work. Commented Jun 2, 2021 at 15:06
  • @jibeeeee I have added config in my question description. Commented Jun 2, 2021 at 15:07
  • the config file looks normal. What do you mean by 404 when refresh? So all the pages can be accessed the first time? Commented Jun 2, 2021 at 15:16

1 Answer 1

0

Can you try if the following works for you?

This is what I use for my SPA.

server {
        listen 8080 default_server;

        root  /var/www/TESTAPP;
        index index.html index.htm;   

        server_name TESTAPP;

        location / {
                try_files $uri $uri/ =404;
        }
}
Sign up to request clarification or add additional context in comments.

Comments

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.