Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tips:ssl [2016/11/10 20:07] – [certificate integration for nginx] scipio | tips:ssl [2022/06/22 07:15] (current) – [letsencrypt staging] sscipioni | ||
---|---|---|---|
Line 5: | Line 5: | ||
[[https:// | [[https:// | ||
+ | ===== letsencrypt staging ===== | ||
+ | |||
+ | get ca certificate and use with curl | ||
+ | <code | download> | ||
+ | API_HOST=sso.csgalileo.org | ||
+ | echo quit | openssl s_client -showcerts -servername " | ||
+ | curl --cacert cacert.pem https:// | ||
+ | </ | ||
+ | |||
+ | in browser import this [[https:// | ||
+ | ===== certbot ====== | ||
+ | |||
+ | < | ||
+ | snap install --classic certbot | ||
+ | |||
+ | # or for focal pre | ||
+ | add-apt-repository ppa: | ||
+ | apt-get update | ||
+ | apt-get install -y certbot python-certbot-nginx | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | certbot certonly --webroot -w / | ||
+ | </ | ||
+ | |||
+ | wildcard | ||
+ | < | ||
+ | certbot certonly \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | ==== nginx ==== | ||
+ | |||
+ | < | ||
+ | server { | ||
+ | listen 80; | ||
+ | server_name nextcloud.csgalileo.org; | ||
+ | server_tokens off; | ||
+ | |||
+ | location / | ||
+ | root /var/www; | ||
+ | allow all; | ||
+ | } | ||
+ | |||
+ | location / { | ||
+ | return 301 https:// | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | server { | ||
+ | listen 443; | ||
+ | server_name nnextcloud.csgalileo.org; | ||
+ | | ||
+ | ssl_certificate / | ||
+ | ssl_certificate_key / | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | renew | ||
+ | < | ||
+ | certbot renew [--dry-run] | ||
+ | </ | ||
+ | |||
+ | automatic renew | ||
+ | < | ||
+ | systemctl status certbot.service | ||
+ | </ | ||
+ | |||
+ | / | ||
+ | < | ||
+ | max-log-backups = 0 | ||
+ | deploy-hook = systemctl reload nginx | ||
+ | </ | ||
===== acme.sh integration for letsencrypt ===== | ===== acme.sh integration for letsencrypt ===== | ||
Line 79: | Line 158: | ||
<file yaml apache.conf> | <file yaml apache.conf> | ||
- | | + | < |
+ | ServerName projects.csgalileo.org | ||
+ | DocumentRoot / | ||
+ | |||
+ | Alias / | ||
+ | < | ||
+ | Options None | ||
+ | AllowOverride None | ||
+ | ForceType text/ | ||
+ | RedirectMatch 404 " | ||
+ | </ | ||
+ | |||
+ | RewriteEngine On | ||
+ | RewriteCond %{REQUEST_URI} !^/ | ||
+ | RewriteRule ^/?(.*) https:// | ||
+ | # Redirect permanent / https:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | # ... | ||
+ | | ||
| | ||
| | ||
| | ||
| | ||
+ | </ | ||
+ | |||
</ | </ | ||
Line 124: | Line 226: | ||
acme.sh --renew | acme.sh --renew | ||
</ | </ | ||
+ | |||
+ | ==== multi server ==== | ||
+ | |||
+ | i can confirm this works. | ||
+ | |||
+ | < | ||
+ | location ~ / | ||
+ | proxy_pass http:// | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | using nginx i added this location to ALL server blocks. | ||
+ | |||
+ | You then run lets encrypt on the machine ctrl.mydomain.com (this machine typically is the controller machine, and is not serving web stuff - its pure purpose from a web POV is to handle incoming cert requests - if you don't know what a controller machine is then read up on ansible) | ||
+ | |||
+ | To make it work I had to use the webroot plugin for Let's Encrypt. I could not get standalone mode to work. | ||
+ | |||
+ | my A records look like .. | ||
+ | |||
+ | < | ||
+ | www01.mydomain.com1 points to 1.2.3.4 | ||
+ | www02.mydomain.com points to 2.3.4.5 | ||
+ | ctrl.mydomain.com points to 3.4.5.6 | ||
+ | mydomain.com points to 1,2,3,4 and 2,3,4,5 (multiple A records) | ||
+ | www.mydomain.com is an alias (cname) for mydomain.com | ||
+ | </ | ||
+ | |||
+ | NGINX runs on www01 and www02 on port 80 to load balance requests (e.g. www01 load balances between www01 and www02, www02 ALSO load balances between www01 and www02) | ||
+ | |||
+ | the above lets encrypt location block is added to NGINX running on both www01 and www02 for all NGINX server blocks | ||
+ | |||
+ | now run lets encrypt in webroot mode (you will need to standup a web server on your controller machine) and request a single certificate for www01.mydomain.com1 www02.mydomain.com mydomain.com www.mydomain.com | ||
+ | |||
+ | when you run this command on your controller machine (ctrl.mydomain.com) it will fireoff a request to each of the 4 domains in return. Every single request will be proxied back to ctrl.mydomain.com via NGINX | ||
+ | |||
+ | bosh! | ||
+ | |||
+ | 2 tips | ||
+ | |||
+ | 1 - to use webroot mode you will need to have a basic web server running on ctrl.domain.com which can serve content from a specified directory | ||
+ | |||
+ | 2 - do not use standalone mode, i could not get it to work | ||
+ | |||
+ | 3 - this solution sits very nicely if you are using ansible, since the certs will live on the controller machine and can be copied across to all slave machines with a single command |