url rewriting - How to do URL rewrite for all URLs except a specific URL using Nginx? -


i have deployed web application in nginx 1.8 , using nginx reverse proxy configuration.

i want following happen. able achieve 1 & 2. how can 5 implemented in nginx configuration ? 3 & 4 sample scenarios of scenario 5

  1. url http://localhost in browser --> have display index.html
  2. url http://localhost/app --> have proxy_pass http://localhost:8081
  3. url http://localhost/login --> have display index.html http://localhost
  4. url http://localhost/dashboard --> have display index.html http://localhost
  5. url http://localhost/anything_other_than_app --> have display index.html http://localhost

my problem is, index.html has login functionality, on successful, login redirects user url http://localhost/dashboard , displays list of users. if user name clicked, redirets http://localhost/user display details.

usecase: if directly type http://localhost/dashboard or http://localhost/user url, nginx searching folder , index page under root , giving 404 error. instead, want display index.html page, has logic display list of users or login page based on session exists or not.

solution used:

location = /index.html {          root   mytestapp;         }         location ~* .*\.png$ {          root   mytestapp;         }         location ~* .*\.jpg$ {          root   mytestapp;                 }         location ~* .*\.css$ {          root   mytestapp;                 }         location ~* .*\.gif$ {          root   mytestapp;                 }         location ~* .*\.js$ {          root   mytestapp;         }             location / {             root   mytestapp;             rewrite ^(.*)$ /index.html;                   }          location /app {             proxy_pass http://localhost:8081;             proxy_set_header host $host;             proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;                        }   

easy

location / {     try_files /index.html =404; }  location /app/ {     # proxy app } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -