🔒Setup SSL Certificate
SSL Certificate setup in linux server
We are going to use dehydrated opensource tools for signing certificates.
STEP 1: Log in as a root to the server.
ssh root@ip_addressSTEP 2: Clone dehydrated Github repo inside /opt/
/opt/cd /opt/ && git clone https://github.com/dehydrated-io/dehydratedSTEP 3: Create dehydrated directory inside /etc/
dehydrated directory inside /etc/cd /etc/ && mkdir dehydratedSTEP 4: Copy config file into /etc/dehydrated/ from docs/examples
cd /dehydrated/ && cp /opt/dehydrated/docs/examples/config .STEP 5: Create .well-known/acme-challenge directory in /var/www/html
mkdir -p /var/www/html/.well-known/acme-challengeSTEP 6: Change the config file as follows
BASEDIR=/etc/dehydrated
WELLKNOWN="/var/www/html/.well-known/acme-challenge"
[email protected]STEP 7: Create domains.txt inside /etc/dehydrated/
echo "yourdomain.com www.yourdomain.com" > domains.txtSTEP 8: Update nginx.conf file with .well-known location
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
...
...
...
location /.well-known {
root /var/www/html;
}
}cd /etc/nginx/sites-available/STEP 9: Restart nginx
systemctl restart nginxSTEP 10: Run Register and Accept terms then Run dehydrated
/opt/dehydrated/dehydrated --register --accept-terms && \
/opt/dehydrated/dehydrated -c STEP 11: Configure server in nginx.conf
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/html;
location / {
return 301 https://ytbot.xyz$request_uri;
}
location /.well-known {
root /var/www/html;
}
}
server {
listen 443 ssl http2;
ssl_certificate /etc/dehydrated/certs/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/dehydrated/certs/yourdomain.com/privkey.pem;
server_name 138.68.5.100 yourdomain.com www.yourdomain.com;
...
...
...
location /.well-known {
root /var/www/html;
}
}
STEP 12: Restart Nginx Server again
systemctl restart nginxSTEP 13: To Renew Certificates setup a weekly cron job
#!/bin/bash
LOGFILE=/var/log/dehydrated_ssl_renew.log
echo -e "\n# $(date -u '+%F %T') $0 $@\n" >> $LOGFILE
/opt/dehydrated/dehydrated -c >> $LOGFILE 2>&1cd /etc/cron.weeklyLast updated
Was this helpful?