Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am unfamiliar with setting up the config and I feel that I've got most of my config right, but there is specific functionality that I can't configure correctly.

What I'm trying to accomplish:

  1. All http(80) traffic redirect to https(443) automatically
  2. I want the server block to work as a "catch-all"
    • Also working as a "catch-all" I want any (http and https) requests for,,, to redirect to so that it will read in the address bar.


What is already working:

  1. http redirect to https (ssl cert config works fine)
  2. will redirect like I want it to.

What is NOT working:

  1. requests for will remain rather than redirecting to

Also there are some things to note:

  1. The public DNS wildcard * resolves to my servers IP
  2. This is main config:
  3. This is the included config:

Does anyone understand how I want it to work, and is it possible with NGINX??

share|improve this question

2 Answers 2

Simply adding a server block for * accessed via ssl should be enough provided your ssl certificate is a wildcard certificate.

server {
    listen                  443 ssl;

    ssl                     on;
    ssl_certificate         /etc/nginx/cert/;
    ssl_certificate_key     /etc/nginx/cert/;
    ssl_session_timeout     15m;
    ssl_protocols           SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers             ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;

    server_name             *;

    return 301$request_uri$is_args$args;
share|improve this answer
I have tried as you suggested and i get this error in various browsers: seems like a redirect loop, is there a way to break the loop? – Ace Feb 15 '13 at 0:40
up vote 0 down vote accepted

The answer provided by Martin was only partially working. It would throw the browser into an infinite redirect loop, which is bad. I did some searching and here is a working config for what i need. here is a full config:

and here is just the partial config that i needed (i dont want to post the whole massively irrelevant config)

    if ($host !~* ^site\.) {  
    return 301$request_uri$is_args$args;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.