在這一章節裏, 我記錄了一下如何在 wamp 環境下配置 sslphp
前提條件git
在設置 Apache + SSL 以前, 須要確認 Apache 已經安裝並能夠正常工做. 而且 ssl 須要的文件在以下的位置:apache
1
2
3
4
5
|
[Apache安裝目錄]/modules/ mod_ssl.so
[Apache安裝目錄]/bin/ openssl.exe, libeay32.dll, ssleay32.dll
[Apache安裝目錄]/conf/ openssl.cnf
|
配置文件修改服務器
1
2
3
|
//去掉下面行首的 # 號
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf
|
用於載入 ssl 模塊和其配置文件dom
認證文件生成ui
在命令行下進入Apache安裝目錄下\bin文件夾,輸入命令:spa
1
2
3
|
//生成證書籤發請求
D:\wamp\apache\bin> openssl req -
new
-out server.csr -config ../conf/openssl.cnf
|
1
2
3
4
5
6
7
8
9
10
|
//回車後要求輸入密碼和確認密碼
Loading
'screen'
into random state - done
Generating a 1024 bit RSA
private
key
......................................................................++++++
........................................++++++
writing
new
private
key to
'privkey.pem'
Enter PEM pass phrase: 123456
Verifying - Enter PEM pass phrase: 123456
-----
|
1
2
3
4
5
6
7
8
9
10
|
//確認密碼輸完回車後, 要求輸入國家縮寫, 只能2個字母
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name
or
a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a
default
value,
If you enter
'.'
, the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
|
1
2
3
|
//要求輸入州名或省名
State
or
Province Name (full name) [Some-State]:Shanghai
|
1
2
3
|
//要求輸入城市名
Locality Name (eg, city) []:Shanghai
|
1
2
3
|
//要求輸入組織名或者公司名
Organization Name (eg, company) [Internet Widgits Pty Ltd]:yiban
|
1
2
3
|
//要求輸入部門名
Organizational Unit Name (eg, section) []:yiban
|
1
2
3
|
//要求輸入服務器域名或IP地址
Common Name (e.g. server FQDN
or
YOUR name) []:yiban
|
1
2
3
|
//要求輸入郵件地址
Email Address []:shawn0828@hotmail.com
|
1
2
3
4
5
|
//要求輸入密碼
Please enter the following
'extra'
attributes
to be sent with your certificate request
A challenge password []:123456
|
1
2
3
|
//要求輸入公司別名
An optional company name []:yiban
|
1
2
3
|
//生成私鑰,輸入命令:
D:\wamp\apache\bin>openssl rsa -in privkey.pem -out server.key
|
1
2
3
4
|
//要求輸入以前 privkey.pem 的密碼
Enter pass phrase
for
privkey.pem: 123456
writing RSA key
|
1
2
3
|
//建立證書,輸入命令:
D:\wamp\apache\bin>openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 8000
|
1
2
3
4
5
6
7
|
//回車後, 顯示建立成功, 有效期爲 8000 天
Loading
'screen'
into random state - done
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=yiban/OU=yiban/CN=yiban/emailAddress=shaw
n0828@hotmail.com
Getting Private key
|
完成後, 將 \bin 下面的 server.csr、server.crt、server.key 拷貝到 [Apache安裝目錄]\conf\ssl 文件夾中, 沒有則建立命令行
再打開 [Apache安裝目錄]\conf\extra\httpd-ssl.conf 文件
替換 SSLCertificateFile 和 SSLCertificateKeyFile 語句對應的路徑,例:code
1
2
3
4
|
#SSLCertificateFile
"D:/wamp/apache/conf/server.crt"
//配置文件默認內容
//替換爲
SSLCertificateFile
"D:/wamp/apache/conf/ssl/server.crt"
|
1
2
3
4
|
#SSLCertificateKeyFile
"D:/wamp/apache/conf/server.key"
//配置文件默認內容
//替換爲
SSLCertificateKeyFile
"D:/wamp/apache/conf/ssl/server.key"
|
最後, 重啓 Apache 服務器orm
在重啓 Apache 時,若遇到 Apache 沒法運行的狀況
1
2
|
能夠運行開始菜單中 Apache HTTP Server 2.2\Configure Apache Server\Test Configuration
來查找 httpd.conf 中的詳細錯誤狀況
|
1
|
或經過查看 Apache 安裝目錄下的 logs 文件夾內的 access.log 和 error.log 中的記錄解決問題
|
若有更好的建議和代碼片斷,歡迎留言提出