為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2016-12 文章編輯:小燈 瀏覽次數(shù):2399
啟用SSL開啟HTTPS訪問已經(jīng)是當(dāng)今的主流趨勢(shì)了,本文旨在提供在nginx上快速配置SSL的簡(jiǎn)易指南。
現(xiàn)在證書越來越便宜,GoDaddy證書只需要幾美元,甚至StartSSL、AlphaSSL、騰訊云或七牛云等都可以免費(fèi)申請(qǐng)到SSL證書。如何申請(qǐng)免費(fèi)證書本文不再贅述。
把申請(qǐng)到的證書文件(包含證書鏈和私鑰)上傳到服務(wù)器,保存到一個(gè)nginx可以讀取到的地方,如/home/ssl/
:
/home/ssl/yourname.cer
為證書鏈/home/ssl/yourname.key
為公鑰在nginx配置文件中,把原來server
塊中的80
端口(http訪問)的語句改為443
端口,并引入SSL各項(xiàng)配置,同時(shí)啟用HSTS(HTTP嚴(yán)格傳輸安全):
server { listen 443 ssl; server_name yourname; root /home/www/yourname; index index.php index.html; ssl_certificate /home/ssl/yourname.crt; ssl_certificate_key /home/ssl/yourname.key;ssl_stapling on; ssl_stapling_verify on;add_header Strict-Transport-Security "max-age=31536000";access_log /var/log/nginx/yourname.log combined;location / { # }}
然后再新建一個(gè)server
塊,目的是把http訪問重定向到https:
server { listen 80; server_name yourname; rewrite ^ https://$host$request_uri? permanent; }
保存后重載nginx即可。
service nginx reload
日期:2018-04 瀏覽次數(shù):6926
日期:2017-02 瀏覽次數(shù):3621
日期:2017-09 瀏覽次數(shù):3889
日期:2017-12 瀏覽次數(shù):3693
日期:2018-12 瀏覽次數(shù):5043
日期:2016-12 瀏覽次數(shù):4749
日期:2017-07 瀏覽次數(shù):13809
日期:2017-12 瀏覽次數(shù):3671
日期:2018-06 瀏覽次數(shù):4432
日期:2018-05 瀏覽次數(shù):4611
日期:2017-12 瀏覽次數(shù):3714
日期:2017-06 瀏覽次數(shù):4134
日期:2018-01 瀏覽次數(shù):4115
日期:2016-12 瀏覽次數(shù):4073
日期:2018-08 瀏覽次數(shù):4569
日期:2017-12 瀏覽次數(shù):3909
日期:2016-09 瀏覽次數(shù):6666
日期:2018-07 瀏覽次數(shù):3356
日期:2016-12 瀏覽次數(shù):3394
日期:2018-10 瀏覽次數(shù):3527
日期:2018-10 瀏覽次數(shù):3644
日期:2018-09 瀏覽次數(shù):3743
日期:2018-02 瀏覽次數(shù):3761
日期:2015-05 瀏覽次數(shù):3678
日期:2018-09 瀏覽次數(shù):3456
日期:2018-06 瀏覽次數(shù):3586
日期:2017-02 瀏覽次數(shù):4029
日期:2018-02 瀏覽次數(shù):4504
日期:2018-02 瀏覽次數(shù):4368
日期:2016-12 瀏覽次數(shù):3718
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.