How to force or redirect to SSL in nginx?

Posted by Callmeed on Server Fault See other posts from Server Fault or by Callmeed
Published on 2011-03-22T18:45:14Z Indexed on 2014/08/23 22:24 UTC
Read the original article Hit count: 209

Filed under:
|
|

I have a signup page on a subdomain like: https://signup.mysite.com

It should only be accessible via HTTPS but I'm worried people might somehow stumble upon it via HTTP and get a 404.

My html/server block in nginx looks like this:

html {
  server {
    listen 443;
    server_name signup.mysite.com;

    ssl                        on;
    ssl_certificate        /path/to/my/cert;
    ssl_certificate_key  /path/to/my/key;

    ssl_session_timeout 30m;

    location / {
      root /path/to/my/rails/app/public;
      index index.html;
        passenger_enabled on;
    }
  }
}

What can I add so that people who go to http://signup.mysite.com get redirected to https://signup.mysite.com ? (FYI I know there are Rails plugins that can force SSL but was hoping to avoid that)

© Server Fault or respective owner

Related posts about nginx

Related posts about redirect