發(fā)表日期:2016-12 文章編輯:小燈 瀏覽次數(shù):2478
啟用SSL開啟HTTPS訪問已經(jīng)是當(dāng)今的主流趨勢了,本文旨在提供在nginx上快速配置SSL的簡易指南。
現(xiàn)在證書越來越便宜,GoDaddy證書只需要幾美元,甚至StartSSL、AlphaSSL、騰訊云或七牛云等都可以免費(fèi)申請到SSL證書。如何申請免費(fèi)證書本文不再贅述。
把申請到的證書文件(包含證書鏈和私鑰)上傳到服務(wù)器,保存到一個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 / { # }}
然后再新建一個server
塊,目的是把http訪問重定向到https:
server { listen 80; server_name yourname; rewrite ^ https://$host$request_uri? permanent; }
保存后重載nginx即可。
service nginx reload
日期:2018-04 瀏覽次數(shù):7014
日期:2017-02 瀏覽次數(shù):3706
日期:2017-09 瀏覽次數(shù):3991
日期:2017-12 瀏覽次數(shù):3791
日期:2018-12 瀏覽次數(shù):5140
日期:2016-12 瀏覽次數(shù):4827
日期:2017-07 瀏覽次數(shù):13890
日期:2017-12 瀏覽次數(shù):3757
日期:2018-06 瀏覽次數(shù):4503
日期:2018-05 瀏覽次數(shù):4687
日期:2017-12 瀏覽次數(shù):3787
日期:2017-06 瀏覽次數(shù):4201
日期:2018-01 瀏覽次數(shù):4194
日期:2016-12 瀏覽次數(shù):4154
日期:2018-08 瀏覽次數(shù):4639
日期:2017-12 瀏覽次數(shù):4007
日期:2016-09 瀏覽次數(shù):6756
日期:2018-07 瀏覽次數(shù):3425
日期:2016-12 瀏覽次數(shù):3467
日期:2018-10 瀏覽次數(shù):3605
日期:2018-10 瀏覽次數(shù):3724
日期:2018-09 瀏覽次數(shù):3831
日期:2018-02 瀏覽次數(shù):3846
日期:2015-05 瀏覽次數(shù):3752
日期:2018-09 瀏覽次數(shù):3525
日期:2018-06 瀏覽次數(shù):3652
日期:2017-02 瀏覽次數(shù):4095
日期:2018-02 瀏覽次數(shù):4598
日期:2018-02 瀏覽次數(shù):4470
日期:2016-12 瀏覽次數(shù):3791
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.