404 Page Not Found on page refresh, It occurs when nginx returns a 404 error if it has no permission to read the requested file or file not available.

404 Page Not Found

Solution: Login to vps/server, navigate to /ect/nginx if already installed if not execute below coomand.

sudo apt update
sudo apt install nginx
  • Open nginx.conf and add below configuration
            listen 80;
            server_name your_domain;
            location / {
                    proxy_pass "http://serverip:portno";
                    proxy_set_header Host your_domain;
                    root   /root/tomcat10/webapps/dist; # angular app
                    try_files $uri $uri/ /index.html;
                    index  index.html index.htm;
  • Save it and restart nginx service, before that check if any error in script.
nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • Now restart or reload nginx server
systemctl restart nginx.service
systemctl reload nginx.service

You should land on default index.html page upon page refresh.


One Reply to “Fix 404 Page Not Found on page refresh”

Leave a Reply

Your email address will not be published. Required fields are marked *