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;
}
}
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
@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
@pixelment
With the server block provided, SSL isn’t configured, thus will not work. If you’re not listening on port 443, then SSL/HTTPS is not active, thus requests for it will result in an error.
Instead of trying to trying to redirect HTTPS => HTTP, I would simply recommend setting up SSL and not worrying about redirects that are typically not standard and may cause issues.