Welcome! Log In Create A New Profile

Advanced

Re: question on server_name_in_redirect

Maxim Dounin
August 25, 2010 07:32AM
Hello!

On Wed, Aug 25, 2010 at 05:08:31PM +0800, bai.xiaoyu@gmail.com wrote:

> server {
> listen 80;
> server_name example.com:7788 example.com;
> server_name_in_redirect on;
> root /var/www/html/exampel/;
> index index.php index.html;
>
> According to the wiki, this should automatically redirect any request
> to example.com to example.com:7788
>
> If server_name_in_redirect is on, then Nginx will use the first value
> of the server_name directive for redirects. If server_name_in_redirect
> is off, then nginx will use the requested Host header.
> http://wiki.nginx.org/NginxHttpCoreModule#server_name_in_redirect
>
> But it didn't work in my case. On nginx 0.8.44

You misunderstood wiki. It says "nginx will use first value ...
for redirects", but it doesn't say anything about "all request
will be redirected". Server name will be only used if nginx
would issue redirect for some reason (e.g. directory redirect to
add trailing slash).

Note well: using port in server_name doesn't make sense as nginx
only match hostname part of a request's Host header against it.
Distinction between different ports is made at socket level.

If you want all requests to port 80 to be redirected to port 7788
you should write something like this:

server {
listen 80;
server_name example.com;
rewrite ^ http://example.com:7788$request_uri?;
}

server {
listen 7788;
server_name example.com;
... here actual request processing ...
}

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

question on server_name_in_redirect

Anonymous User August 25, 2010 05:14AM

Re: question on server_name_in_redirect

Maxim Dounin August 25, 2010 07:32AM

Re: question on server_name_in_redirect

Anonymous User August 25, 2010 10:28PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 313
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