Skip to content

Instantly share code, notes, and snippets.

@dashr
Last active January 20, 2016 06:40
Show Gist options
  • Save dashr/c2dff10f4edb82f904b1 to your computer and use it in GitHub Desktop.
Save dashr/c2dff10f4edb82f904b1 to your computer and use it in GitHub Desktop.
Nginx: Send all 80 to 443
# /etc/nginx/sites-available/production <-- in same VirtualHost container as the 443 one, above it
server {
listen 80;
server_name sample.com www.sample.com;
rewrite ^(.*) https://sample.com$1 permanent;
}
@devnore
Copy link

devnore commented Jan 20, 2016

As stated in http://nginx.org/en/docs/http/converting_rewrite_rules.html it is ineffective to use rewrite when no actual rewriting is done.

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

Just adding this information here if someone comes across it in search for information on how to do it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment