I need to config nginx reverse proxy to listen 443 port and redirect to localhost and port from url address. Https://example.com/test/1234 Redirect to 127.0.0.1:1234 And it means client choose port on local host by writing in url.
Asked
Active
Viewed 612 times
0
-
1Why do you want to redirect (HTTP 30x) to `127.0.0.1:1234`? The people browsing `https://example.com/test/1234` might not have a web server/web app running at `127.0.0.1:1234` on their machines. – Lex Li Jan 03 '23 at 03:47
-
Actually I have vpn runing on my server and every user have a port on my vpn server.so the client vpn app request on port 443 and its request url contains port number. I want nginx redirects its request to servers port which he requested. – Ehsan Hosseini Jan 03 '23 at 09:52
-
Maybe try something like `location ~ ^/test/([0-9]{4}?)(/.*)?$ { proxy_pass http://127.0.0.1:$1/$2; }` i would guess without testing it. And i just searched and think that would still go wrong with [this in mind](https://serverfault.com/questions/649151/nginx-location-regex-doesnt-work-with-proxy-pass). – Jan 03 '23 at 10:43
-
When your VPN server opens that port, does it allow local traffic only (binding to 127.0.0.1)? Or external traffic is also acceptable? You cannot redirect if the VPN server only expects local traffic, and in that case `proxy_pass` is required like crpb commented. – Lex Li Jan 03 '23 at 18:20