I'm trying to use proxy_pass in nginx to forward requests to another port on localhost like this:
location /foo {
rewrite ^/foo/(.*) /$1 break;
proxy_pass http://127.0.0.1:8080/;
}
location /bar {
rewrite ^/bar/(.*) /$1 break;
proxy_pass http://localhost:8080/;
}
location /blah {
rewrite ^/blah/(.*) /$1 break;
proxy_pass http://192.168.77.56:8080/;
}
So only the last one works. The first two give me a page-unavailable error. I know the endpoint is working as I can go directly to localhost:8080 and see output I expected.
Any idea what I'm doing wrong?
[Edit]: Further enlightenment... It seems the rewrite line has something to do with it. Using it like I have here seems to work on non-localhost IPs, i.e. it removes /blah from the path and keeps the rest as it sends it to its final destination. If I remove the rewrite line I can proxy to localhost (of course losing my indented other stuff on the url).
The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.
To redirect a URL in a website running on an Nginx server, you must manually create a redirects. conf file. In this file will then add your redirect code.
This worked:
location /blah {
rewrite ^/blah/(.*) /$1 break;
proxy_pass http://$server_addr:8080;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With