Nick's Blog

Nginx is running, but http traffic is not redirecting to https

If you running a nginx reverse proxy in conjunction with Lets encrypt. You may want to get all your traffic encrypted for free, Since you’ve already had the certificate installed.

You have plenty of options in term of configuring your reverse proxy. In this case, I just choose to use one.

When you configure your nginx configuration. You need to have two server policy, one is taking care of the ssl traffic and the certification location. The other is use to redirect the http to redirect to https.

I have made a mistake that accidentally put one server policy nested in to another server policy. In that case, your nginx server will failed to start.

Jan 27 22:34:28 ip-172-25-5-211 systemd[1]: Failed to start A high performance web server and a reverse proxy server.

Please avoid it, and let get straight into the configuration. I’m just going to show the second part (the redirection part). [Before you make any change, it always good to backup your existing configuration.]

server {
    listen 80 default_server;

    server_name _;

    return 301 https://$host$request_uri;
}

And restart your nginx server, the change will applied. And you should have all http traffic redirect to https.