Question

http-https redirect / Positive SSL on nginx

  • Posted on October 8, 2014
  • DianaMAsked by DianaM

Hi guys,

This is my first time here asking questions, untill now I read and learned from the best of you. So, I installed Ubuntu 14.04 on my Droplet, configured EasyEngine on it with nginx / php5-fpm and fastcgi. I bought a Positive SSL from namecheap and now I want to use it on my Wordpress site. So I put the ssl-bundle.crt and the domain_com.key in /var/www/domain.com/cert and after that I modified the file in /etc/nginx/sites-available/domain.com and put the following configuration:

# WPSINGLE FAST CGI NGINX CONFIGURATION

server {
        listen 80;
        listen 443 ssl;
        server_name devly.co www.devly.co;
        ssl on;
        ssl_certificate /var/www/devly.co/cert/ssl-bundle.crt;
        ssl_certificate_key /var/www/devly.co/cert/devly_co.key;
        access_log   /var/log/nginx/devly.co.access.log rt_cache;
        error_log    /var/log/nginx/devly.co.error.log;
        root /var/www/devly.co/htdocs;
        index index.php index.htm index.html;

        include common/wpfc.conf;
        include common/wpcommon.conf;
        include common/locations.conf;

# force https-redirects
    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
}


}

The thing is, the redirect doesn’t work, if I enter http://domain.com it won’t automaticaly redirect to https. What did I do wrong ? Also any recomendations ? My first time using SSL on a server.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Instead of specifying your http and https sites in the same server block I would recommend formatting your configuration in two server blocks, one for http and one for https.

server {
       listen         80;
       server_name    my.domain.com;
       return         301 https://$server_name$request_uri;
}

server {
       listen         443 ssl;
       server_name    my.domain.com;

       [....]
}

If you are using CloudFlare HTTPS

server {
   ...
   if ($**http_x_forwarded_proto** = "http") {
     return 301 https://$server_name$request_uri;
   }
   ... 
}

Peace!

hello, more one question about redirect

when put ip address for example http://ipofsitewithssl rediret to https://mysite but whe try access https://the ip address not redirect and load the site

this is my config

server { listen 80; server_name mydomain.com.br www.mydomain.com.br; return 301 https://www.mydomaincom.br$request_uri; }

server { listen 80; server_name my ip xx.xx.xx.xx; return 301 https://www.mydomain.com.br$request_uri; }

server { listen 443; server_name www.mydomain.com.br; ssl on; ssl_certificate /var/www/mydomain.com.br/cert/www_selfbox_com_br.crt; ssl_certificate_key /var/www/mydomain.com.br/cert/www_selfbox_com_br.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;