Last active
June 9, 2021 19:57
-
-
Save gene1wood/f8031f186b84915ae01d to your computer and use it in GitHub Desktop.
Example of how to setup Let's Encrypt on RHEL / CentOS and automate certificate rewnewal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[email protected] | |
DOMAINS=example.com,www.example.com,foo.example.com,example.org.example.net,www.example.org,www.example.net | |
git clone https://github.com/letsencrypt/letsencrypt | |
cd letsencrypt/ | |
mkdir -p /var/lib/letsencrypt/global-webroot | |
# Setup the global alias | |
echo "Alias /.well-known/acme-challenge /var/lib/letsencrypt/global-webroot/.well-known/acme-challenge" >> /etc/httpd/conf/httpd.conf | |
apachectl configtest && apachectl graceful | |
# Create the cron job | |
cat > /etc/cron.monthly/renew-letsencrypt.sh <<End-of-message | |
#!/bin/bash | |
DOMAINS=$DOMAINS | |
/root/.local/share/letsencrypt/bin/letsencrypt certonly --agree-tos --renew-by-default --webroot --webroot-path /var/lib/letsencrypt/global-webroot --domains \$DOMAINS && /usr/sbin/apachectl graceful | |
# On CentOS/RHEL 6 running Python 2.6 add the "--debug" argument | |
End-of-message | |
chmod 755 /etc/cron.monthly/renew-letsencrypt.sh | |
# Install letsencrypt by running it the first time and generate the cert | |
./letsencrypt-auto certonly --agree-tos --email $EMAIL --renew-by-default --webroot --webroot-path /var/lib/letsencrypt/global-webroot --domains $DOMAINS | |
# On CentOS/RHEL 6 running Python 2.6 add the "--debug" argument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SSLEngine on | |
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem | |
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem | |
Header always set Strict-Transport-Security "max-age=15768000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VirtualHost *:443> | |
# This VirtualHost shows how to bypass the reverse proxy with ProxyPassMatch | |
SSLEngine on | |
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem | |
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem | |
Header always set Strict-Transport-Security "max-age=15768000" | |
DocumentRoot /var/www/html | |
ServerName example.com | |
ProxyRequests Off | |
ProxyPreserveHost On | |
<Proxy *> | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
# Add this to allow Let's Encrypt to validate control of the site | |
ProxyPassMatch ^/\.well-known/acme-challenge/.* ! | |
ProxyPass / http://localhost:8080/ connectiontimeout=300 timeout=300 | |
ProxyPassReverse / http://localhost:8080/ | |
</VirtualHost> | |
<VirtualHost *:443> | |
# This VirtualHost shows how to bypass the reverse proxy with RewriteRule | |
SSLEngine on | |
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem | |
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem | |
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem | |
Header always set Strict-Transport-Security "max-age=15768000" | |
DocumentRoot /var/www/html | |
ServerName example.com | |
ProxyRequests Off | |
ProxyPreserveHost On | |
<Proxy *> | |
Order deny,allow | |
Allow from all | |
</Proxy> | |
<Proxy balancer://myapp> | |
BalancerMember http://127.0.0.1:8080 | |
</Proxy> | |
# Add this to allow Let's Encrypt to validate control of the site | |
RewriteRule ^/\.well-known/acme-challenge/.*$ - [last] | |
RewriteRule ^/(.*)$ balancer://myapp%{REQUEST_URI} [P,QSA,L] | |
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOMAINS=example.com,www.example.com,foo.example.com,example.org.example.net,www.example.org,www.example.net | |
/root/.local/share/letsencrypt/bin/letsencrypt certonly --agree-tos --renew-by-default --webroot --webroot-path /var/lib/letsencrypt/global-webroot --domains $DOMAINS && /usr/sbin/apachectl graceful |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This seems to be missing a step. The installation of certbot itself once it's cloned. Is this outdated or have I missed something obvious?