前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux centos debain nginx自动ssl证书配置 软件 snapd

linux centos debain nginx自动ssl证书配置 软件 snapd

原创
作者头像
eisc
发布2022-03-06 22:37:37
1.1K0
发布2022-03-06 22:37:37
举报

nginx 自动ssl证书配置

 #    1. 安装ssl 证书软件

yum install -y snapd

apt install snapd

# 1.安装snapd 

yum reinstall -y snapd

# 重新安装 snapd,确保您的 snapd 版本是最新的

systemctl enable --now snapd.socket

# 安装后,需要启用管理主 snap 通信套接字的systemd单元

snap install core;

# 安装核心如果报错请检查第一步

snap refresh core   

# 刷新核心 

snap install --classic certbot

# 安装证书机器人

# sudo apt-get remove certbot、sudo dnf remove certbot或sudo yum remove certbot。

# 如果您使用apt、dnf或yum等操作系统包管理器安装了任何 Certbot 包 ,则应在安装 Certbot snap 之前将其删除,以确保在运行命令 certbot 时使用的是 snap,而不是从您的操作系统包安装经理。

 ln -s /var/lib/snapd/snap /snap

# 软连接(快捷方式)已经安装的软件 snap 到 要求的路径snap :经典限制要求在/snap或symlink下使用快照

snap install --classic certbot

# 安装证书机器人

ln -s /snap/bin/certbot /usr/bin/certbot

# 将证书机器人安装目录创建快捷方式到 运行目录  /usr/bin/certbot  (软连接)

# 删除快捷方式,删除软连接  rm -rf /usr/bin/certbot

 #    2. 申请ssl 证书

# certbot --nginx

# 自动配置nginx ssl 证书,会修改nginx 配置文件,输入电子邮箱,后回车确认

# 运行此命令以获取证书并让 Certbot 自动编辑您的 Nginx 配置以提供服务,只需一步即可打开 HTTPS 访问

certbot certonly --nginx

# 我们选择只获得nginx 证书,手动配置,将来源的ssl 证书删除,然后将自动下载的ssl 创建软链接(快捷方式)到原来的ssl 文件

# 1: Keep the existing certificate for now

# 暂时保留现有证书

# 2: Renew & replace the certificate (may be subject to CA rate limits)

# 更新和更换证书(可能受CA费率限制)  2

# agree in order to register with the ACME server. Do you agree?

# 同意在ACME服务器上注册。你同意吗?  y

# Would you be willing, once your first certificate is successfully issued, toshare your email address with the Electronic Frontier Foundation,

# 一旦您的第一份证书成功颁发,您是否愿意分享你的电子邮件地址与电子前沿基金会,成立Let's Encrypt项目的合作伙伴和机器人  no

# Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):

# 选择以逗号和/或空格分隔的适当数字,或保留输入 空白选择显示的所有选项(输入“c”取消):

# Successfully received certificate.

# Certificate is saved at: /etc/letsencrypt/live/www.eisc.cn/fullchain.pem

# Key is saved at:         /etc/letsencrypt/live/www.eisc.cn/privkey.pem

# 证书的位置如上图,自动修改nginx 子站点的 ssl 路径,每三个月自动更新ssl 

# 由于是链接的国外  R3 证书颁发机构,可能存在失败的情况,需要重试

rm -rf /eisc/www/ssl/eisc/eisc.pem

rm -rf /eisc/www/ssl/eisc/eisc.key

# 删除原有ssl 证书文件

ln -s /etc/letsencrypt/live/www.eisc.cn/fullchain.pem /eisc/www/ssl/eisc/eisc.pem

ln -s /etc/letsencrypt/live/www.eisc.cn/privkey.pem /eisc/www/ssl/eisc/eisc.key

nginx -s reload

# 重载nginx 配置文件

教程来源:https://www.cnblogs.com/hushuning/p/14842251.html

 #    查看 nginx 配置信息

server{

listen 443 ssl;

server_name www.eisc.cn eisc.cn;

    ssl_certificate /etc/letsencrypt/live/eisc.cn/fullchain.pem; # managed by Certbot

    ssl_certificate_key /etc/letsencrypt/live/eisc.cn/privkey.pem; # managed by Certbot 

    #ssl on;

    ssl_session_timeout 5m;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;

location / {

proxy_pass https://eisc.cn;

index index.php index.html;

#------------- 可见ip ------------#

     proxy_set_header Host $host;

     proxy_set_header X-Real-IP $remote_addr;

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

server{

    if ($host = eisc.cn) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

    if ($host = www.eisc.cn) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

listen 80;

server_name www.eisc.cn eisc.cn;

    return 404; # managed by Certbot

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • nginx 自动ssl证书配置
    •  #    1. 安装ssl 证书软件
      •  #    2. 申请ssl 证书
        •  #    查看 nginx 配置信息
        相关产品与服务
        SSL 证书
        腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档