Reverse proxy and rewrite. Need help !
Igor Sysoev
igor at sysoev.ru
Fri Mar 5 17:36:06 MSK 2010
On Fri, Mar 05, 2010 at 05:32:11PM +0300, Igor Sysoev wrote:
> On Fri, Mar 05, 2010 at 03:18:17PM +0100, Da Blitter wrote:
>
> > Hey ,
> >
> > I have two domains, domain.net and domain.com and considering the
> > expected lack of IP addresses I want to setup a sites hub/reverse proxy.
> > Nginx 0.7.6x is installed on a debian 5.x box and works fine so far. Now
> > I’m stuck with this 4 cases scenario:
> >
> > 1. www.domain.net ----> nginx ------(no rewrite)------>
> > internal-www.domain.net box
> > Nginx should pass the whole url to the internal box. Here’s my config
> > server {
> > listen 80;
> > server_name www.domain.net;
> >
> > #charset koi8-r;
> >
> > access_log logs/www.domain.net.access.log;
> >
> > location / {
> > proxy_pass http://internal-www.domain.net;
> > proxy_redirect off;
> > proxy_set_header Host $host;
> > proxy_set_header X-Real-IP $remote_addr;
> > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> > }
> >
> > 2. www.domain.com ----> nginx ------(rewrite)------>
> > internal-com.domain.net box
> > nginx should rewrite the base url (http://www.domain.com to
> > http://com.domain.net before passing it to the internal box)
> > ex : http://www.domain.com/index.html rewritten to
> > http://com.domain.net/index.html and send to the box
> >
> > 3. pub.domain.net/alias1 ----> nginx ------(rewrite)------>
> > internal-pub.domain.net box
> > nginx should rewrite the url to remove the “/alias1” part before passing
> > it to the internal box (which is a drupal site…).
> > ex : http://pub.domain.net/alias1/index.php rewritten to
> > http://pub.domain.net/index.php and send to the box
> >
> > 4. pub.domain.net/alias2 ----> nginx ------(rewrite)------>
> > internal-alias2.domain.net box
> > nginx should rewrite the url from pub.domain.net/alias2 to
> > alias2.domain.net part before passing it to the internal box
> > ex: http://pub.domain.net/alias2 rewritten to http://alias2.domain.net
> > and send to the box.
> >
> > After some hair pulling, a lot of “Should I use proxy_pass or
> > proxy_redirect ?” and “is drupal messing with something”, any help would
> > be really appreciated.
>
> proxy_set_header Host $host;
"Host" is probably is not needed.
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
> server {
> server_name www.domain.net;
> location / {
> proxy_pass http://internal-www.domain.net;
> }
> }
>
> server {
> server_name www.domain.com;
> location / {
> proxy_pass http://internal-com.domain.net;
> }
> }
>
> server {
> server_name pub.domain.net;
> location /alias1/ {
> proxy_pass http://internal-pub.domain.net/;
> }
> location /alias2/ {
> proxy_pass http://internal-alias2.domain.net/;
> }
> }
Also you should not disable proxy_redirect, if backend send such redirects:
Location: http://internal-www.domain.net/some/url
Location: http://internal-pub.domain.net/another/url
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list