ssl redirect issue

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

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

> Actually, I can work around this issue by adding:
> if ($host !~* ^($ ) {
> rewrite ^(.*)$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 {
   return 301$request_uri;

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

server {
    listen 443 ssl;

    # remaining server config...

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

Additional reading:

--- appa

More information about the nginx mailing list