how to avoid nginx not found 404 error ubuntu react app 1

how to avoid nginx not found 404 error ubuntu react app

location / {
            root /var/www/myapp/build;
            index index.html;
            try_files $uri /index.html$is_args$args =404;
    }

Here is what the above code is Doing:
1. We’re telling Nginx to listen on port 80.
2. We’re telling Nginx to serve static files from the /var/www/myapp/build directory.
3. We’re telling Nginx to serve index.html as the default file.
4. We’re telling Nginx to rewrite all requests to /index.html.

Now, we need to create a symbolic link to the Nginx configuration file we just created.

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/

Now, we need to restart Nginx.

sudo service nginx restart

Now, we need to create a systemd service file for our React app.

sudo nano /etc/systemd/system/myapp.service

Similar Posts