標籤:
開啟httpd.conf檔案,移除注釋的行:
Include conf/extra/httpd-ahssl.conf
LoadModule ssl_module modules/mod_ssl.so
ServerName mytsbank.com:80
開啟httpd-ahssl.conf,修改如下:
<VirtualHost _default_:443>
SSLEngine on
ServerName mytsbank.com:443 #主要修改一下這裡
SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
DocumentRoot "C:/AppServ/www"
# DocumentRoot access handled globally in httpd.conf
CustomLog "${SRVROOT}/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
<Directory "C:/AppServ/www">
Options Indexes Includes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</virtualhost>
重啟apache,輸入https://www.mytsbank.com
apache 配置https
1、安裝好apache環境,注意要裝ssl版本的。這裡裝在c:/apache目錄下。
2、產生伺服器憑證
1)在DOS命令下進入apache/bin目錄
2)在windows環境下需先設定Openssl環境變數:
執行命令
set OPENSSL_CONF=..\conf\openssl.cnf
請在執行之前確保C:\AppServ\Apache24\conf\openssl.cnf 存在,否則會出現:WARNING: can‘t open config file: /usr/local/ssl/openssl.cnf 資訊提示。
還有在windows系統下.cnf 預設會被當成捷徑,看不到副檔名。
3)產生私密金鑰檔案:
執行命令
openssl genrsa 1024>server.key
說明:這是用128位rsa演算法產生密鑰,得到server.key檔案。 > 是輸出檔案的標識符
這種產生方法產生的是沒有密鑰的私密金鑰檔案。當然,Apache提供了加入密鑰(Password)的命令,就是加入參數-des3。命令為:
openssl genrsa 1024 -des3 > server.key
使用上述命令產生私密金鑰檔案是需要輸入密鑰的,啟動並執行時候會讓你輸入並確認你的密鑰。但是在Windows環境下會導致以下錯誤:錯誤:Apache啟動失敗,錯誤提示是:Init: SSLPassPhraseDialog builtin is not supported on Win32 (key file .....)
原因是window下的apache不支援加密的私密金鑰檔案。
註:產生的認證中RSA金鑰組的預設長度是1024,取值是2的整數次方。建議使用4096以上。
4)產生認證請求檔案。
執行命令
openssl req -new -key server.key > server.csr
說明:這是用步驟3的密鑰產生認證請求檔案server.csr, 這一步會有很多參數,需要一一輸入。
按提示輸入一系列的參數:
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 []:[email protected] 管理員郵箱
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!? )
5)簽署伺服器憑證檔案。
執行命令列
openssl req -x509 -days 365 -key server.key -in server.csr > server.crt
說明:這是用步驟3,4的的密鑰和認證請求產生認證server.crt,-days參數指明認證有效期間,單位為天,x509表示產生的為X.509認證。
以上籤署認證僅僅做測試用,真正啟動並執行時候,應該將CSR發送到一個CA返回真正的認證。網上有些文檔描述產生認證檔案的過程比較繁瑣,就是因為 他們自己建立了一個CA中心,然後再簽署server.csr
用openssl x509 -noout -text -in server.crt 可以查看認證的內容。認證實際上包含了Public Key
3、配置httpd.conf
開啟httpd.conf檔案,移除注釋的行:
Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
appserv 配置ahssl