ubuntu使用certbot给nginx添加ssl证书

首先确认网站部署完成,已经能通过80端口访问

安装certbot

sudo apt install certbotsudo snap install --classic certbot

执行

sudo certbot --nginx

  • 如果出现如下提示:
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    The requested nginx plugin does not appear to be installed
    安装这个包解决:
    apt install python3-certbot-nginx

第一次执行需要填个邮箱来注册,所有步骤如下

// 1. 输入你的邮箱
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): xxx@xxx.com   
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// 2. 是否同意服务条款,输入y
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y    

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// 3. 是否同意接收推送邮件,输入y或n
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n
Account registered.

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: xxxxx.com
2: yyyyy.com

// 4. 选择给nginx配置中的域名添加证书,输入序号选择,或直接回车选择所有
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 
Requesting a certificate for xxxxx.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/xxxxx.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/xxxxx.com/privkey.pem
This certificate expires on 2022-08-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for xxxxx.com to /etc/nginx/sites-enabled/xxxx
Congratulations! You have successfully enabled HTTPS on xxxxx.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// 5.结束,可直接访问https站点
手动更新证书

sudo certbot renew

证书有效期为3个月,默认到期前会自动更新,修改配置后需手动更新

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要配置Nginx反向代理和SSL证书,您可以按照以下步骤进行操作: 1. 首先,确保您已经在Linux系统上安装了Nginx。您可以使用以下命令在Ubuntu上进行安装: ``` sudo apt update sudo apt install nginx ``` 2. 为了配置反向代理,您需要编辑Nginx的配置文件。默认情况下,Nginx的配置文件位于`/etc/nginx/nginx.conf`或`/etc/nginx/conf.d/default.conf`。您可以使用以下命令打开配置文件: ``` sudo nano /etc/nginx/nginx.conf ``` 3. 在配置文件中,找到`http`块,并在其中添加以下内容来配置反向代理: ``` server { listen 80; server_name your_domain.com; location / { proxy_pass http://backend_server; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } ``` 将`your_domain.com`替换为您的域名,并将`backend_server`替换为您要代理的后端服务器的地址。 4. 保存并关闭配置文件。然后,重新加载Nginx配置以使更改生效: ``` sudo systemctl reload nginx ``` 5. 接下来,您需要配置SSL证书以启用HTTPS。您可以使用免费的Let's Encrypt证书进行配置。首先,安装Certbot工具: ``` sudo apt install certbot ``` 6. 然后,运行以下命令获取和安装证书: ``` sudo certbot certonly --nginx -d your_domain.com ``` 将`your_domain.com`替换为您的域名。 7. Certbot将自动处理证书的生成和Nginx配置的更新。完成后,您的SSL证书将被安装并配置在Nginx中。 现在,您已经成功配置了Nginx的反向代理和SSL证书

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值