nginx部署https

目前很多web應(yīng)用都有https的需求,或者作為小程序的服務(wù)端,也必須使用https,接下來以nginx為例,講解一下如何把自己的域名變?yōu)閔ttps的安全域名
1.申請ssl證書(略過),
申請通過后將下載下來的ssl證書文件(兩個)

例:

2.將下載的這兩個文件,上傳到服務(wù)器nginx配置文件夾下的ssl(目錄),我這里是(ssl是自己建的文件夾)
/usr/local/nginx/conf/ssl

上傳方法自行百度
3.修改vhost里對應(yīng)域名的配置文件

# vim vhost/www.woann.cn.conf 
#上邊的這個server是后加的,為了把http訪問強(qiáng)行跳轉(zhuǎn)到https
server {
    listen 80;
    server_name www.woann.cn woann.cn;
    index index.html index.php index.htm;


    return      301 https://$server_name$request_uri;
    }
#下邊這個server做了一些改動(除了注釋部分,其他保持你自己原來的不需改動)
server
    {
        listen 443;#端口由原來的80改為443
        server_name www.woann.cn woann.cn;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/blog;

        include none.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php-pathinfo.conf;
        location / {
            if (!-e $request_filename) {
                rewrite ^(.*)$ /index.php?s=$1 last;
                break;
            }
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

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

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/www.woann.cn.log;
        #以下是添加ssl相關(guān)配置項 自行更改對應(yīng)參數(shù)
        ssl on;
        ssl_certificate ssl/1_www.woann.cn_bundle.crt;#證書文件
        ssl_certificate_key ssl/2_www.woann.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;
}

4.保存之后重啟nginx即可



如果有不懂得地方可以聯(lián)系咨詢下
qq: 304550409
微博: 吳同學(xué)吖

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容