HTTP directory redirect not using $host
Igor Sysoev
is at rambler-co.ru
Wed Sep 20 03:03:43 MSD 2006
On Tue, 19 Sep 2006, Bob Ippolito wrote:
> It seems that the redirection from http://example.com/somedir to
> http://example.com/somedir/ does a 302 using the local hostname rather
> than the Host header.
>
> I was able to work around the issue using rewrite:
> if (-d $request_filename) { rewrite ^(.*[^/])$ http://$host$1/; }
>
> It would be nice if this was fixed in a future release. I looked
> around in the source for a bit, but I wasn't able to find exactly what
> needs to be changed.
Had you set "server_name" ?
server {
server_name example.com www.example.com;
...
}
server {
server_name example1.com www.example1.com;
...
}
nginx uses first name of the "server_name" directive in redirect.
If server_name is not set, then it uses local hostname.
If you have an wildcard server you can force nginx to use always
the "Host" header in redirects using "*":
server {
server_name example.com *;
...
}
The "*" could not be first name. You need to set something,
it may be even dummy name "_":
server_name _ *;
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list