http 升级为 https 访问

1.获取免费的CA证书。
laravel项目配置https访问以及遇到的坑
2.然后填写信息申请
laravel项目配置https访问以及遇到的坑
3.下载对应证书
laravel项目配置https访问以及遇到的坑
4.上传证书到你的服务器

cd usr/local/nginx/conf/vhost
mkdir cert 
将.key和.pem后缀文件上传到cert文件夹,并重命名xxx.key,xxx.pem

5.配置nginx(最好把之前80端口的配置备份一份)

server
    {
        listen 443 ssl;
        server_name    xxxxxxxx;//你备案好的域名
        index index.html index.htm index.php default.html default.htm default.php;
        root xxxxxxx;#项目目录
        ssl_certificate  cert/cfun.pem;
        ssl_certificate_key cert/cfun.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;
        include rewrite/y.conf;
        include enable-php-pathinfo.conf;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location / {
        index index.php index.html index.htm;
        if (!-e $request_filename) {
                rewrite  ^/(.*)$  /index.php?s=$1  last;
                break;
              }
        }
        location ~ /\.
        {
            deny all;
        }
        access_log  /home/wwwlogs/y.log;
    }
 server {
         listen 80;
         server_name  xxxxxxxx;//你备案好的域名; 
         access_log  /home/wwwlogs/y.log;
         rewrite ^(.*)$ https://$host$1 permanent; #把http的域名请求转成https
}
       }

Nginx 支持 rewrite 功能。若您在编译时没有去掉 pcre,您可在 HTTP 的 server 中增加
rewrite ^(.*) https://$host$1 permanent;即可将默认80端口的请求重定向为 HTTPS。

6.重启nginx,访问域名:www.xxx.com .自动跳转https安全访问;如图
Laravel 项目配置 免费 https 访问
7.总结:第一次听别人说配安全证书,心生羡慕,有一种来自菜鸟的仰慕。当你接触了才发现,原来如此。。。哈哈。多动手,多思考。Believe in yourself, everything is the beginning of the best!

本作品采用《CC 协议》,转载必须注明作者和本文链接
cfun
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 1

Nginx的https还没有配置过,学习了 :relaxed:

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!