Welcome! Log In Create A New Profile

Advanced

Help ! rewriteRule with proxy flag

Posted by rook2pawn 
Help ! rewriteRule with proxy flag
March 04, 2011 03:49AM
hi all,

I have the following that im trying to get working in Nginx but its not quite working out..


RewriteCond %{$REQUEST_URI} ^/foo
RewriteRule ^/(.*) http://127.0.0.1:4500/$1 [P,L] #proxy and last
RewriteCond %{$REQUEST_URI} ^/$
RewriteRule ^/$ http://foobar.com/foo

any ideas? Thanks in advance.



Edited 1 time(s). Last edit at 03/04/2011 03:51AM by rook2pawn.
Re: Help ! rewriteRule with proxy flag
March 04, 2011 04:52AM
actually i just found a good solution. perhaps by sharing it can be evaluated and or be helpful to others. 3 location blocks did it and it looks proper.

location ~ ^/foo {
proxy_pass http://127.0.0.1:4500
}
location ~ ^/$ {
rewrite ^/$ http://bar.com/foo
}
location / {
root /path/to/www
}

so what this setup achieves i think is to rewrite a / request to /foo which proxies to port 4500 and appears to come from /foo while all other traffic that isnt requesting / goes directlyy without interference. ill just say i have a good reason for rewriting to /foo before proxying just that but this is good example of how to simulate a selective proxypass.. comments?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 128
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready