Wednesday 16 November 2016

NginX and Aungular js : Manully type url or page refresh then throw 404 error but routing works

Problem : We have website www.xyz.com - when we hit this browser redirect to www.xyz.com/login but if we refresh page or manully type url www.xyz.com/login  server throw 404 error.
or  say
page refresh give 404 error


Solution: Nigix conf  just above the close curly bracket add
error_page 404 =200 /index.html;

Sample
server {
    listen       80;
        root   /var/www;
    location / {
    }
    error_page 404 =200 /index.html;
}


We are changing response code to 200 ok and redirecting user to index.html which is our default home page :)

Source
http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page