Nginx rewrite host
Igor Sysoev
is at rambler-co.ru
Wed Feb 11 13:10:06 MSK 2009
On Wed, Feb 11, 2009 at 11:06:17AM +0100, Tomasz Pajor wrote:
> So from You are saying is should replace:
>
> server {
> listen 8080;
> location / {
> set $my_host $host;
> if ($host ~* "(.+\.nl.test.com|.+\.test.nl|test.nl)") { rewrite
> ^ http://nl.test.com$request_uri last; }
> proxy_pass http://apps; proxy_set_header Host $my_host;
> }
> }
>
> with
>
> server {
> listen 8080;
> server_name *.nl.test.com test.nl *.test.nl;
> rewrite ^ http://nl.test.com$request_uri last;
> }
>
> yes?
Yes. And "test.nl" and "*.test.nl" can be combined in one ".test.nl".
Also you do not need
set $my_host $host;
use just
proxy_pass http://apps;
proxy_set_header Host $host;
> --
> Tom Pajor
>
> >On Wed, Feb 11, 2009 at 10:31:38AM +0100, Tomasz Pajor wrote:
> >
> >
> >>if ($host !~* "(blah.com|blah2.com)") {
> >> rewrite ^(.*)$ http://blah.com$1 break;
> >>}
> >>
> >>Reference:
> >>http://wiki.codemongers.com/NginxHttpRewriteModule#if
> >>
> >
> >Never! Never use "if" just to test $host.
> >There is special very optimized directives server/server_name:
> >
> > server {
> > server_name blah1.com blah2.com;
> > rewrite ^ http://blah.com$request_uri;
> > }
> >
> >
> >>--
> >>Tom Pajor
> >>
> >>
> >>>Hello!
> >>>
> >>>
> >>>
> >>>How can I add 2 or more host?
> >>>
> >>>
> >>>
> >>>*From:* owner-nginx at sysoev.ru [mailto:owner-nginx at sysoev.ru] *On
> >>>Behalf Of *Kingsley Foreman
> >>>*Sent:* 11 Februari 2009 15:26
> >>>*To:* nginx at sysoev.ru
> >>>*Subject:* Re: Nginx rewrite host
> >>>
> >>>
> >>>
> >>> if ($host != blah.com){
> >>> rewrite ^(.*)$ http://blah.com$1 break;
> >>> }
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>*From:* Glen Lumanau <mailto:glen at lumanau.web.id>
> >>>
> >>>*Sent:* Wednesday, February 11, 2009 3:14 PM
> >>>
> >>>*To:* nginx at sysoev.ru <mailto:nginx at sysoev.ru>
> >>>
> >>>*Subject:* Nginx rewrite host
> >>>
> >>>
> >>>
> >>>Hello!
> >>>
> >>>
> >>>
> >>>How can I create this rule
> >>>
> >>>If host = 127.0.0.1, 127.0.0.2
> >>>
> >>>Do nothing
> >>>
> >>>
> >>>
> >>>If host != 127.0.0.1, 127.0.0.2
> >>>
> >>>Rewrite bla bla bla
> >>>
> >>>
> >>>
> >>>Thank you for any help
> >>>
> >>>
> >>>
> >>>
> >
> >
>
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list