使用SSL安全证书和nginx配置将域名HTTPS化

本文详细介绍了如何在阿里云上申请SSL证书,并将其部署到Nginx服务器的过程。包括证书申请、域名解析、配置Nginx等步骤,确保网站从HTTP平滑过渡到HTTPS,提升网站安全性。

一、在阿里云后台申请免费版证书:

二、在域名解析里面添加记录:

三、提交审核:

四、等待审核通过后,下载nginx证书:

五、按照文档修改nginx配置文件:

  https://help.aliyun.com/knowledge_detail/95491.html?spm=a2c4g.11186623.2.12.35e134f1kGVUlT

  1、进入本地命令行,将本地的证书文件远程传送到服务器,记得加上端口:

   scp -P 8290 ./1652724_www.locusy.top.key root@47.94.208.76:/root/

   scp -P 8290 ./1652724_www.locusy.top.pem root@47.94.208.76:/root/ 

  2、在服务器端查看文件是否拷贝成功:

  3、在/ect/nginx目录下新建文件夹cert :

    mkdir cert

  4、将证书文件加到/etc/nginx/cert文件夹下面:

    mv 1652724_www.locusy.top.key /etc/nginx/cert/

    mv 1652724_www.locusy.top.pem /etc/nginx/cert/

  5、服务器端进入nginx配置的目录:

    /etc/nginx/conf.d

  6、打开www-locusy-top.conf文件,配置如下:


server {
        listen 80;
        server_name www.locusy.top;
        root /www/temp/blog/public/client;
        index index.html;
        location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$ {
                root /www/temp/blog/public;
        }
        rewrite ^(.*)$  https://$host$1 permanent;
#       return 301 https://www.locusy.top$request_uri;
}

server {
        listen 443;
        server_name www.locusy.top;
        ssl on;
        ssl_certificate   cert/1652724_www.locusy.top.pem;
        ssl_certificate_key  cert/1652724_www.locusy.top.key;
        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;
        root /www/temp/blog/public/client;
        index index.html;
        location ~ .*\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt)$ {
                root /www/temp/blog/public;
        }

#       if ($ssl_protocol = "") {
#               rewrite ^(.*) https://$host$1 permanent;
#       }
}
 

  7、检查nginx配置问题:

    nginx -t

  8、重启nginx:

    nginx -s reload

六:打开网址测试,跳转到https成功:

  

  

转载于:https://www.cnblogs.com/angelatian/p/10167722.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值