Skip to content

Instantly share code, notes, and snippets.

@marcelino-m
Last active September 24, 2018 07:26
Show Gist options
  • Save marcelino-m/06a2387d4fba7ad6ab56704d1c8e32d7 to your computer and use it in GitHub Desktop.
Save marcelino-m/06a2387d4fba7ad6ab56704d1c8e32d7 to your computer and use it in GitHub Desktop.
Example of a nginx conf using Let's Encrypt
# Virtual Host configuration for myorg.cl
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/myhost.myorg.cl/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myhost.myorg.cl/privkey.pem;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=31536000";
server_name myhost.myorg.cl;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
location /.well-known {
alias /var/www/html/captor/.well-known;
}
location / {
proxy_pass http://127.0.0.1:8081;
}
}
@lsaavedr
Copy link

lsaavedr commented Sep 24, 2018

put this in /etc/nginx/snippets/letsencrypt.conf file

ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=31536000";

# Redirect to HTTPS
if ($scheme = http) {
  return 301 https://$server_name$request_uri;
}

# Allow access to '^/.well-known/'
location ~ ^/.well-known/ {
    allow all;
    access_log off;
    log_not_found off;
    autoindex off;
    root /var/www/html;
}

and then in your example (without the proxy settings that is another snippet)...

...
        ssl_certificate /etc/letsencrypt/live/myhost.myorg.cl/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/myhost.myorg.cl/privkey.pem;
        include snippets/letsencrypt.conf;
...

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