Nginx - redirecting www.example.com/test to www.example.com//000/

If I have a domain, for example, http://www.example.com , and I would like to redirect all requests from http://www.example.com/test to http://www.example.com:3000 , how to do it right?
I tried the following:

 location /test { proxy_pass http://www.example.com:3000; proxy_set_header Host $host; } 

But what he does really redirects http://www.example.com/test to http://www.example.com:3000/test , and that is not what I want.
How can I do it right?

UPDATE:
While Krizna answer worked, it redirects me to my domain as expected.
But now I want my browser bar to be http://www.example.com/test instead of http://www.example.com:3000 . If I understand correctly, I have to install nginx to catch the answer and send it back to the URL requested by the user. How to do it?

+4
source share
2 answers

try this code

 location / { rewrite ^/test(/.*)$ http://example.com:3000$1 permanent; proxy_set_header Host $host; } 

Updated: if you do not want to rewrite the url, try this code ..

 server { -------- server_name www.example.com; location /test { proxy_pass http://example.com:3000; } } 
+4
source

proxy_redirect off should solve your problem. It will pass, but will not change the URI.

Documentation: http://wiki.nginx.org/HttpProxyModule#proxy_redirect

 location /test { proxy_pass http://example.com:3000; proxy_set_header Host $host; proxy_redirect off; } 
+1
source

Source: https://habr.com/ru/post/1483748/


All Articles