nginx – 404 on refresh

When you have configured a vhost for your site it might happen that when you access your application using your host name for eg http://<host-name>/ it all works good. Also you would be able to browse through links with in your app. The problem comes when you are in a path  for eg http://<host-name>/some/path and you hit refresh you get a 404 error page. After a lot of digging finally found this on github issues. This extra line in the vhost could save your day.

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

After adding do a nginx service restart and everything works great !

Nginx 403 forbidden

Though you have set all permissions right for files and folders which nginx needs to access you might face with the strange 403 error. That would be probably because of the SELinux. You would probably need to set enforce level to permissive. Run this command :

# setenforce Permissive

This will set the particular enforce level till reboot. Or else you can choose to change the SELinux context for your directory alone using this :

# chcon -Rt httpd_sys_content_t /path/to/www

Remember to change back the enforce level after using above command. This is the original stackoverflow post.