Question

Nginx https to http

I have an issue with a freshly configured Nginx setup on Ubuntu 16.04. My site loads fine using http, but I get a connection refused error when I access it using https. I don’t need https at the moment, so I would like to redirect these request to http.

My server block looks almost exactly like the LEMP tutorial (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04) with the addition of a condition that checks for https, then redirects to http. For some reason, this is not working for me. Any help would be appreciated!

See my edited down server block:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        server_name domain.com www.domain.com;

        if ( $https = "on" ) {
                return 301 http://$host$request_uri;
        }
}

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.

Accepted Answer

@pixelment @jtittle You should setup Lets Encrypt - and keep your site on HTTPS-only (with a redirect from HTTP). There’s multiple advantages to HTTPS - first is that it allows http/2, which is version 2 of the HTTP protocol. This will speed up your site a lot, since all files on the site’s connection is streamed through the same tunnel. And search engines are actually preferring HTTPS, so you’ll get a lower ranking if you don’t have it.

This comment has been deleted

    Do you have a certificate or are you using Lets Encrypt? Can you post all the configuration - it’s okay if you change your domain name to domain.com

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.