Skip to content

Instantly share code, notes, and snippets.

@lengerfulluse
Created January 3, 2018 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lengerfulluse/d15d50ff1bd7fe973ff48ada12935b05 to your computer and use it in GitHub Desktop.
Save lengerfulluse/d15d50ff1bd7fe973ff48ada12935b05 to your computer and use it in GitHub Desktop.
configure ssl redirect for nginx
# http part
server {
listen 80;
listen [::]:80;
root /var/www/hengwei.me/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name hengwei.me www.hengwei.me;
return 301 https://$server_name$request_uri;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
# ssl part
server {
root /var/www/hengwei.me/html;
index index.html index.htm;
server_name hengwei.me;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/hengwei.me/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/hengwei.me/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment