美文网首页
ubuntu使用Let’s Encrypt设置https

ubuntu使用Let’s Encrypt设置https

作者: wwmin_ | 来源:发表于2018-05-03 23:58 被阅读117次

    Let’s Encrypt Let’s Encrypt is a free, automated, and open Certificate Authority.
    进入主页后点击Getting Started菜单后点,选择安装方式,这里我选择了 with shell access并使用Certbot的安装方式certbot(点击链接进入)

    certbot
    进入certbot网站后,选择对应的自己的系统和服务:
    certbot
    在下面就会自动出现相应的安装方法:
    1. 首先安装相应的package:
    sudo apt-get update
    sudo apt-get install software-properties-common
    sudo add-apt-repository ppa:certbot/certbot
    sudo apt-get update
    sudo apt-get install python-certbot-nginx
    

    即下图所示中的命令


    nginx on ubuntu

    然后执行

    sudo certbot --nginx
    

    一路agree和yes,并输入自己的网站名称,和自己的邮箱以及选择http跳转方式(2),
    最终会出现Congratulations! You have successfully enabled https://www.example.com字样,
    恭喜你!你的网站已经加密成功了!

    certbot --nginx
    certbot --nginx

    并且网站已经启动了过期自动更新机制.
    也可以用如下命令做测试

    $ sudo certbot renew --dry-run
    

    这下就完全搞定了!

    给二级域名添加encrypt

    在/etc/nginx/sites-available/ 下新建名为mysecondsite(示意)文件,将以下内容拷贝进去

    server {
        root /var/lib/jenkins/workspace/webTools/dist;
        # listen 80;
        server_name tools.wwmin.top;
          location /{
            index index.html;
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            # try_files $uri $uri/ /index.html last; # 此种方法在linux下有时也会报错,
            #解决方法见https://www.jianshu.com/p/05f889faa74b?from=timeline&isappinstalled=0
            if (!-e $request_filename) {
                rewrite ^/(.*) /index.html last;
                break;
           }
       }
    }
    

    然后输入一下命令,在sites-enabled文件夹下建立mysecondsite文件的链接

    ln -s /etc/nginx/sites-available/mysecondsite  /etc/nginx/sites-enabled/
    

    此时就需要加密这个二级域名网站了
    在控制台中输入

    certbot --nginx
    

    按照certbot提示选中刚建立的二级域名网址,后续步骤同上.
    如果在选项中没有出现刚建立的二级域名网址,说明sites-enabled下没有刚建立的链接,需要建立之后在重试.
    最后再重启nginx即可

    service nginx restart
    nginx -s reload
    //如果是用supervisor管理的nginx进程可以重新加载
    supervisorctl restart nginx
    

    相关文章

      网友评论

          本文标题:ubuntu使用Let’s Encrypt设置https

          本文链接:https://www.haomeiwen.com/subject/vvlrrftx.html