Cài Certbot – Nginx tự động gia hạn SSL Let’s Encrypt
08/03/2022 80 lượt xemCài nginx trước
+ Link hướng dẫn: How To Install Nginx on Ubuntu 16.04 | DigitalOcean
Cài Certbot – Nginx
+ First, add the repository.
sudo add-apt-repository ppa:certbot/certbot
+ You’ll need to press ENTER to accept. Then, update the package list to pick up the new repository’s package information.
sudo apt-get update
+ And finally, install Certbot’s Nginx package with apt-get.
sudo apt-get install python-certbot-nginx
+ Certbot is now ready to use, but in order for it to configure SSL for Nginx, we need to verify some of Nginx’s configuration.
Tạo nginx block và cài ssl
Tạo nginx block
+ Tạo file tên domain dưới máy vd: abc.com rồi dán block sau vào
server {
listen [::]:80;
listen 80;
server_name abc.com www.abc.com;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://115.112.483.130:10010;
}
location ~* /web/static/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://115.112.483.130:10010;
}
}
** Đổi domain abc.com thành domain của bạn
** Thay port chỗ Ip:10010 thành port chạy domain bạn muốn dùng cho chạy nhiều web trên 1 vps
+ Upload file này lên đường dẫn /etc/nginx/sites-available
+ Chạy lệnh sau để tạo link sang sites-enable
ln -s /etc/nginx/sites-available/abc.com /etc/nginx/sites-enabled/
** abc.com là tên file bạn đã tạo và up lên sites-available
Cài ssl bằng certbot
+ Reload nginx
sudo systemctl reload nginx
+ Cài SSL
sudo certbot --nginx -d example.com -d www.example.com
** Thay example.com bằng domain của bạn
