个人网站配置HTTPS

1 篇文章 0 订阅
1 篇文章 0 订阅
让NGINX支持SSL

需要编译时支持ssl,可以sbin/nginx -V 来查看confiture参数,如果当时没有支持,那么需要重新编译安装。 编译参数前面已经有一篇文章了。nginx编译参数,也不用全加,用--with-http_ssl_module 就可以了。

生成证书

主要参考这个letsencrypty,可以生成免费证书。 生成方式也很简单,读上面的文章基本就能明白。ubuntu+nginx.

大致步骤如下:

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto
./path/to/certbot-auto certonly --webroot -w /var/www/example -d example.com -d www.example.com -w /var/www/thing -d thing.is -d m.thing.is

执行完之后系统中会生成这些文件。系统中生成的文件

This command will obtain a single cert for example.com, www.example.com, thing.is, and m.thing.is; it will place files below /var/www/example to prove control of the first two domains, and under /var/www/thing for the second pair.
Automating renewal

上面生成的证书,有效期好像是1个月,所以需要到期自己重新renewal一下。方法如下:

./path/to/certbot-auto renew --dry-run
./path/to/certbot-auto renew --quiet --no-self-upgrade
配置NGINX

配置就不多说了.首先需要配置2个server,监听2个端口。这样可以强制将80端口的请求重定向至443端口。https本身监听的是443端口。最主要的是ssl中间那3行。将步骤2中生成的对应key写在nginx的配置文件里。注意改成你的具体路径。

server {

    listen       443;
    server_name  blog.nofile.cc;

    ssl                  on;
    ssl_certificate      /xxxx/letsencrypt/live/yoursite/fullchain.pem;
    ssl_certificate_key  /xxxx/letsencrypt/live/yoursite/privkey.pem;

     location / {
        #这个地方指定被访问的文件夹位置
        root   /your/webroot/;
        index  index.html;
    }
}

server {
    listen      80;
    server_name blog.nofile.cc;
    return 301 https://blog.nofile.cc$request_uri;  
}

配置好之后,重启nginx,应该就可以看到绿色的锁了。
我的个人网站https://blog.nofile.cc,欢迎来踩。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值