Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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 www.example.com, example.com, bob.example.com, -randomstring-.example.com to redirect to site.example.com so that it will read https://site.example.com in the address bar.

.

What is already working:

  1. http redirect to https (ssl cert config works fine)
  2. http://-randomstring-.example.com will redirect https://site.example.com like I want it to.

What is NOT working:

  1. requests for https://-randomstring-.example.com will remain rather than redirecting to https://site.example.com

Also there are some things to note:

  1. The public DNS wildcard *.example.com resolves to my servers IP
  2. This is main config: http://pastebin.com/rqzQDwyD
  3. This is the included config: http://pastebin.com/D87R6LJK

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 *example.com 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/_.example.com-chained.pem;
    ssl_certificate_key     /etc/nginx/cert/_.example.com.key.insecure;
    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             *.example.com;

    return 301 https://site.example.com$request_uri$is_args$args;
}
share|improve this answer
    
I have tried as you suggested and i get this error in various browsers: i.imgur.com/J9B1Onx.png 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: http://pastebin.com/ngPUH5P2

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 https://site.example.com$request_uri$is_args$args;
    }
share|improve this answer

Your Answer

 
discard

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.