question on server_name_in_redirect

bai.xiaoyu at gmail.com bai.xiaoyu at gmail.com
Thu Aug 26 06:23:31 MSD 2010


Thank you for your explanation!  Your solution is much elegant!

I have a follow up on this.  Since the redirect is used for "issue
redirect for some reason (e.g. directory redirect to  add trailing
slash).", then, supposedly i can do this:

    location ~ ^/download/.*$  {
    # the rewrite works!
    rewrite ^ http://example.com:7788$request_uri?;
    }

It works! :)  Thank you!  Now the site is running on deafutl port 80.
Users won't notice the download is through port 7788 unless they look
at the header.  Much better!

> 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 at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



More information about the nginx mailing list