技術(shù)頻道導(dǎo)航
HTML/CSS
.NET技術(shù)
IIS技術(shù)
PHP技術(shù)
Js/JQuery
Photoshop
Fireworks
服務(wù)器技術(shù)
操作系統(tǒng)
網(wǎng)站運營

贊助商

分類目錄

贊助商

最新文章

搜索

使用OpenSSL為Nginx配置HTTPS證書

作者:admin    時間:2017-4-5 12:3:17    瀏覽:

OpenSSL官方推薦win32可執(zhí)行文件版下載:

 OpenSSL

一、證書制作

1、制作CA證書:

ca.key CA私鑰:

openssl genrsa -des3 -out ca.key 2048

制作解密后的CA私鑰(一般無此必要):

openssl rsa -in ca.key -out ca_decrypted.key

ca.crt CA根證書(公鑰):

openssl req -new -x509 -days 7305 -key ca.key -out ca.crt

2、制作生成網(wǎng)站的證書并用CA簽名認(rèn)證

在這里,假設(shè)網(wǎng)站域名為www.howtostagehomes.com

生成www.howtostagehomes.com證書私鑰:

openssl genrsa -des3 -out www.howtostagehomes.com.pem 1024

制作解密后的www.howtostagehomes.com證書私鑰:

openssl rsa -in www.howtostagehomes.com.pem -out www.howtostagehomes.com.key

生成簽名請求:

openssl req -new -key www.howtostagehomes.com.pem -out www.howtostagehomes.com.csr

在common name中填入網(wǎng)站域名,如www.howtostagehomes.com即可生成改站點的證書,同時也可以使用泛域名如*.webkaka.com來生成所有二級域名可用的網(wǎng)站證書。

用CA進(jìn)行簽名:

openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in www.howtostagehomes.com.csr -out www.howtostagehomes.com.crt

其中,policy參數(shù)允許簽名的CA和網(wǎng)站證書可以有不同的國家、地名等信息,days參數(shù)則是簽名時限。

如果在執(zhí)行簽名命令時,出現(xiàn)“I am unable to access the ../../CA/newcerts directory

修改 /etc/pki/tls/openssl.cnf 中“dir = ./CA

然后:

mkdir -p CA/newcerts

touch CA/index.txt

touch CA/serial

echo "01" > CA/serial

再重新執(zhí)行簽名命令。

最后,把ca.crt的內(nèi)容粘貼到www.howtostagehomes.com.crt后面。這個比較重要!因為不這樣做,可能會有某些瀏覽器不支持。

好了,現(xiàn)在https需要到的網(wǎng)站私鑰www.howtostagehomes.com.key和網(wǎng)站證書www.howtostagehomes.com.crt都準(zhǔn)備完畢。接下來開始配置服務(wù)端。

二、配置Nginx服務(wù)器

新開一個虛擬主機(jī),并在server{}段中設(shè)置:

listen 443;

ssl on;

ssl_certificate /path/to/www.howtostagehomes.com.crt;

ssl_certificate_key /path/to/www.howtostagehomes.com.key;

其中的路徑是剛剛生成的網(wǎng)站證書的路徑。

然后使用一下命令檢測配置和重新加載nginx:

    檢測配置:

nginx -t

    重新加載:

nginx -s reload

三、優(yōu)化nginx配置

1、優(yōu)化nginx性能

http{}中加入:

ssl_session_cache shared:SSL:10m;

ssl_session_timeout 10m;

據(jù)官方文檔所述,cache中的1m可以存放4000個session。

在配置https的虛擬主機(jī)server{}中加入:

keepalive_timeout 70;

2、有時在phpMyAdmin等程序登入后會錯誤地跳轉(zhuǎn)http的問題。

解決方法是定位至 “location ~ .*\.(php|php5)?${}” 在include fcgi.conf;或者在fastcgi_param配置后面加上:

fastcgi_param HTTPS on;

fastcgi_param HTTP_SCHEME https;

在這里是nginx官方的關(guān)于https的文檔:

 https文檔

可以作為參考。

=====================================

本文文章來源是:http://blog.creke.net/762.html,經(jīng)網(wǎng)友測試證實方法可用,有疑問可到博主網(wǎng)頁上交流。如下為部分網(wǎng)友的反饋。

 

 

=====================================

您可能對以下文章也感興趣

標(biāo)簽: nginx  https  linux技術(shù)  
x
  • 站長推薦
/* 左側(cè)顯示文章內(nèi)容目錄 */