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/ and after that I modified the file in /etc/nginx/sites-available/ and put the following configuration:


server {
        listen 80;
        listen 443 ssl;
        ssl on;
        ssl_certificate /var/www/;
        ssl_certificate_key /var/www/;
        access_log   /var/log/nginx/ rt_cache;
        error_log    /var/log/nginx/;
        root /var/www/;
        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 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;
       return         301 https://$server_name$request_uri;

server {
       listen         443 ssl;


If you are using CloudFlare HTTPS

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


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; return 301$request_uri; }

server { listen 80; server_name my ip xx.xx.xx.xx; return 301$request_uri; }

server { listen 443; server_name; ssl on; ssl_certificate /var/www/; ssl_certificate_key /var/www/; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;