windows配置openssl

下載openssl並安裝,下載地址:http://slproweb.com/products/Win32OpenSSL.htmlphp

假設安裝路徑爲C:\"Program Files"\OpenSSL-Win64\bin\openssl.exehtml

若是沒有加入系統環境變量,下面的命令裏的openssl要換成安裝路徑的值web

1、生成祕鑰算法

openssl genrsa 1024 > server.keyapache

這是用128位rsa算法生成密鑰,獲得server.key文件 > 是輸出文件的標識符flask

2、生成未簽署的server.csr 瀏覽器

openssl req -new -key server.key > server.csr服務器

這是用步驟1的密鑰生成證書請求文件server.csr, 這一步會有不少參數,須要一一輸入app


Country Name (2 letter code) [AU]:CN ISO國家代碼(只支持兩位字符)
State or Province Name (full name) [Some-State]:ZJ所在省份
Locality Name (eg, city) []:HZ所在城市
Organization Name (eg, company):SW_TECH公司名稱
Organizational Unit Name (eg, section) []:SW_TECH組織名稱
Common Name (eg, YOUR name) []:kedou.com申請證書的域名
Email Address []:admin@admin.com 管理員郵箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: 交換密鑰
An optional company name []:  注:Common Name必須和httpd.conf中server name必須一致,不然apache不能啓動 (啓動apache時錯誤提示爲:RSA server certificate CommonName (CN) `Kedou' does NOT match server name!? )dom


 4、簽署服務器證書文件server.crt
openssl req -x509 -days 365 -key server.key -in server.csr > server.crt 
說明:這是用步驟1,2的的密鑰和證書請求生成證書server.crt,-days參數指明證書有效期,單位爲天,x509表示生成的爲X.509證書。


5、這一步可選,配置apache的httpd.conf.
在conf目錄下的httpd_ssl.conf文件是關於ssl的配置,是httpd.conf的一部分,在 httpd.conf中找到給文件的引用,移除對應的註釋
Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so

修改httpd-ssl.conf文件 並配置
SSLCertificateFile "D:/phpStudy/Apache/conf/ssl/server.crt" (具體的服務器地址)
SSLCertificateKeyFile "D:/phpStudy/Apache/conf/ssl/server.key" (具體的服務器地址)
CustomLog "D:/PHPStudy/Apache/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

配置
<VirtualHost _default_:443>

# General setup for the virtual host
DocumentRoot "D:/PHPStudy/WWW/" (域名帶訪問的目錄)
ServerName www.rgweb.com:443 (域名)
ServerAdmin admin@admin.com (管理員郵箱)
ErrorLog "D:/PHPStudy/Apache/logs/ssl_error.log.txt" (寫入日誌)
TransferLog "D:/PHPStudy/Apache/logs/ssl_trans_error.log.txt" (寫入日誌)

至此重啓apache 
瀏覽器輸入 https 加你配置的域名

注:錯誤:WARNING: can't open config file: /apache24/conf/openssl.cnf

解決:將openssl_conf 放入環境變量  set openssl_conf=../conf/openssl.cnf

錯 :Unable to write ‘random state 

解決:是由於沒有用管理員進入cmd,使用管理員身份進入cmd 就解決了

6、用flask等程序的話直接調用生成證書便可

flask使用證書,若是報ssl錯誤,需注意證書在代碼裏的位置是否有調換,

'server.crt','server.key'這兩個證書出如今代碼裏的位置不能夠調換
app.run('0.0.0.0', debug=True, port=5000, ssl_context=('server.crt','server.key'))
相關文章
相關標籤/搜索