How can I setup nginx to reverse proxy a single folder to one server and the rest of root to a different server?
The root "/" is managed by CMS while the "other" is my own programs (independent of the CMS).
Here is my current configuration
server {
listen 80;
server_name www.example.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
... <ssl stuff> ...
server_name www.example.com;
location /other {
proxy_pass http://192.168.2.2/other ;
}
location / {
proxy_pass http://192.168.1.1;
}
}
reference to nginx docs:
http://wiki.nginx.org/HttpCoreModule#location
http://wiki.nginx.org/HttpProxyModule#proxy_pass
You should change the other
location to this:
location /other/ {
proxy_pass http://192.168.2.2/other/ ;
}
Note the trailing /
. It actually make a difference since it gets proxy_pass
to normalize the request. I quote:
when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the [proxy_pass] directive.
This should help those that find this page.
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