Peter Green Asked: 2017-04-21 06:40:15 +0800 CST2017-04-21 06:40:15 +0800 CST 2017-04-21 06:40:15 +0800 CST How can I make nginx redirect (not proxy) traffic to a different port 772 I want to redirect (not proxy) requests for a list of hostnames to a different port using my nginx server how do I do this? nginx 1 Answers Voted Best Answer Peter Green 2017-04-21T06:40:15+08:002017-04-21T06:40:15+08:00 To send a redirect one uses return 302, the requested hostname and path can be picked up using $host and $request_uri So the complete config for the vhost looks like server { listen 5.153.225.231:80; listen [2001:41c9:1:3ce::1:10]:80; listen 5.153.225.231:443 ssl; listen [2001:41c9:1:3ce::1:10]:443 ssl; server_name tracker.raspbian.org; server_name tracker-bm.raspbian.org; return 302 http://$host:8000$request_uri; }
To send a redirect one uses
return 302
, the requested hostname and path can be picked up using$host
and$request_uri
So the complete config for the vhost looks like