自己服务服务器在腾讯云,又想着出了免费的 ssl 证书,也弄一个玩玩,下面是完整记录

1.申请免费证书,有经济条件的可以买一个支持多域名的,我这穷逼只能白嫖免费的了,阿里云腾讯云我记得都有免费的了,下面一切以腾讯云为记录,阿里云应该差不多

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

nginx 配置 https 访问 随笔 第1张

nginx 配置 https 访问 随笔 第2张

密码一定记好 不支持找回

然后直接下一步 腾讯会审核 一般都挺快的 我两个小时就好了

2,下载证书,上传到服务器

审核完成是第一张图那样子的,点下载,会有个压缩包,解压后是几个文件夹,包含不同的服务器,这里取 nginx

nginx 配置 https 访问 随笔 第3张

 

把这两个文件上传到 nginx 配置目录下 这里每个人都不一样 看自己而定  我的在下图这里

nginx 配置 https 访问 随笔 第4张

 

3,接下来就只剩配置文件了

这里也是取你当前域名的配置文件,也可能你直接都写到 nginx.conf 里了,那就直接配置 nginx.conf , 配置完成如下

nginx 配置 https 访问 随笔 第5张

 

 

 80 端口的访问全部重定向到 https   

 rewrite ^(.*) https://$host$1 permanent;

代码如下

server {
       listen       80;
       server_name  xxxx.cn www.xxxx.cn;

       rewrite ^(.*) https://$host$1 permanent;
}


 server {
       listen       443;
       server_name  www.xxxx.cn;
       ssl on;
       ssl_certificate 1_www.xxxx.cn_bundle.crt;
       ssl_certificate_key 2_www.xxxx.cn.key;
       ssl_session_timeout 5m;
       ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
       ssl_ciphers ECDHE-RSA-AES128-GCM-    SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
       ssl_prefer_server_ciphers on;

       #rewrite ^(.*) https://$host$1 permanent;        

       # Load configuration files for the default server block.

       location / {
                        root /xxx;
                        index index.html index.htm ;
       }

 

       error_page 404 /404.html;
                        location = /40x.html {
       }
    }

 

4.重启 nginx 服务器,就能正常访问了   

 

大部分取自官方文档 https://cloud.tencent.com/document/product/400/4143  还是挺简单的  里面有 apache 和 tomcat 的配置方法,应该也不是很难

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄