Bidyut
Bidyut

Reputation: 993

Nginx Redirect to root for nginx

I am running nginx which is listening on port number 9000.

The redirect rules are as follows:

  1. Anything to / should go to index.html.
  2. Anything to /rest should forward the request to background service.
  3. Anything apart from rule 1 and rule 2 should forward to rule 1 or index.html

My sample nginx configuration file is as follows:

 server {
 listen       9000;
 server_name  localhost;

 location / {
     root   /usr/share/nginx/html;
     index  index.html index.htm;
 }

 error_page 404 403 405 500 502 503 504 = @notfound;

 location /rest {
      proxy_pass http://localhost:12000;
 }

 location @notfound {
     return 301 http://localhost/;
 }
}

My redirect is not working properly, and it will redirect to http://localhost instead of http://localhost:9000.

Can anybody point out where am I doing the mistake.

Upvotes: 2

Views: 923

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

return 301 http://localhost/; should be return 301 http://localhost:9000/;

Upvotes: 1

Related Questions