Skip to content

Instantly share code, notes, and snippets.

@sayanriju
Created November 25, 2019 11:50
Show Gist options
  • Save sayanriju/e68fdf5c3fb25e686c42f54c7cabf7c9 to your computer and use it in GitHub Desktop.
Save sayanriju/e68fdf5c3fb25e686c42f54c7cabf7c9 to your computer and use it in GitHub Desktop.
NGINX Virtual Host Config with http->https redirection (Certbot)
server {
server_name example.com;
root /home/ls/app/;
index index.html;
location / {
try_files $uri $uri/ =404;
# try_files $uri /index.html =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name example.com;
return 404; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment