ssl redirect issue

António P. P. Almeida appa at perusio.net
Thu Sep 22 12:41:08 UTC 2011


On 22 Set 2011 12h23 WEST, atistler at gmail.com wrote:

> Actually, I can work around this issue by adding:
>
> if ($host !~* ^(my.example.net)$ ) {
> rewrite ^(.*) https://my.example.net$1 permanent;
> }
>
> I am curious however this does not work when I put the redirect in
> the default ( '_' ) server config

'_' is a not a valid hostname. The reason it's used in the recommended
configuration for default servers is that there's no risk of colliding
with anything else and you can have individual vhost configs for each
proper hostname. 

Your config should be something like this:

server {
   server_name my.example.net;
   return 301 https://myexample.net$request_uri;
}

Then you should have the regular HTTPs server config that listens on
port 443.

server {
    listen 443 ssl;
    server_name my.example.net;

    # remaining server config...
}

Repeat the above for each domain redirect you want to have.

Additional reading:
http://nginx.org/en/docs/http/configuring_https_servers.html
http://nginx.org/en/docs/http/server_names.html

--- appa



More information about the nginx mailing list