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

贊助商

分類目錄

贊助商

最新文章

搜索

使用OpenSSL為Nginx配置HTTPS證書

作者:admin    時(shí)間:2017-4-5 12:3:17    瀏覽:

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

 OpenSSL

一、證書制作

1、制作CA證書:

ca.key CA私鑰:

openssl genrsa -des3 -out ca.key 2048

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

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

生成簽名請(qǐng)求:

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

在common name中填入網(wǎng)站域名,如www.howtostagehomes.com即可生成改站點(diǎn)的證書,同時(shí)也可以使用泛域名如*.webkaka.com來(lái)生成所有二級(jí)域名可用的網(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)站證書可以有不同的國(guó)家、地名等信息,days參數(shù)則是簽名時(shí)限。

如果在執(zhí)行簽名命令時(shí),出現(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后面。這個(gè)比較重要!因?yàn)椴贿@樣做,可能會(huì)有某些瀏覽器不支持。

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

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

新開一個(gè)虛擬主機(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)站證書的路徑。

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

    檢測(cè)配置:

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個(gè)session。

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

keepalive_timeout 70;

2、有時(shí)在phpMyAdmin等程序登入后會(huì)錯(cuò)誤地跳轉(zhuǎn)http的問(wèn)題。

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

fastcgi_param HTTPS on;

fastcgi_param HTTP_SCHEME https;

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

 https文檔

可以作為參考。

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

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

 

 

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

您可能對(duì)以下文章也感興趣

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