当前位置:首页 > 大杂烩 > 正文内容

nginx配置https,nginx ssl配置

高老师8年前 (2017-07-18)大杂烩1792

首先在阿里云申请免费的证书,选择自动生成证书。然后就是nginx虚拟主机配置文件的修改。以下是我的配置文件(因为公司开发小程序,没有办法只能使用https)。

您只需要关注带有ssl的配置选项,我增加了一个监听80和443的端口,同时增加了http跳转https的配置

server
    {
        listen 443;
        listen 80;


        
        server_name yasi.baimuv.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /data/wwwroot/yasi;

        #强制https
        if ($scheme = http) {
            return   301 https://$host$request_uri;
        }

        #Https配置区域
        ssl on;
        ssl_certificate  ../cert/214198214130804.pem;
        ssl_certificate_key ../cert/214198214130804.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;        
        #Https配置区域结束


        include none.conf;
        #error_page   404   /404.html;
        location ~ [^/]\.php(/|$)
        {
            # comment try_files $uri =404; to enable pathinfo
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            #include pathinfo.conf;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        access_log off;
    }

如果无法访问请检查:

        1.443端口公网是否已经开放

        2.证书文件位置是否正确

        3.不要怀疑其他问题,基本是你配置不对。

成功后的效果:

        QQ图片20170718221820.png

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/483.html

分享给朋友:

“nginx配置https,nginx ssl配置” 的相关文章

c#中string和StringBuilder效率对比

c#中string和StringBuilder效率对比

    c#中string和StringBuilder直接看看执行速度。(2).String类型累计赋值Test               ...

Git推送文件到远程仓库

Git推送文件到远程仓库

1.远程仓库的协作模式开发者把自己最新的版本推到线上仓库,同时把线上仓库的最新代码,拉到自己本地即可2.注册git帐号国外: http://www.github.com国内: http://git.oschina.net2.在码云创建项目,不要初始化readmegit push https://gi...

Git从远程仓库更新文件

Git从远程仓库更新文件

 git   pull  https://git.oschina.net/392223903/learn.git   master   换为您的git地址...

Git日志查看和版本切换

Git日志查看和版本切换

日志查看:git log版本切换:方式1:git  reset  --hard  HEAD^   倒退一个版本git  reset  --hard  HEAD^^  倒退两个版本方式2:(版本号的形式,建议版本号码补充完...

c#关闭计算机的代码

c#关闭计算机的代码

    1.关机Process.Start("shutdown", "-s -t 0");    2. 注销  Proc...

c#中文简体转换繁体

c#中文简体转换繁体

private const string fantizi = "高久峰是個程序員"; private const string jiantizi = "高久峰是个程序员...