Windows下配置Apache的SSL服務 到 Apache的網站上 下載下傳包含有 SSL 服務的安裝包。
如果你已經安裝過了Apache,在安裝含有SSL服務的Apache 伺服器之前需要 解除安裝已經安裝過的。到控制台裡面直接解除安裝就可以了。 注意:Apache在解除安裝的時候不會删除httpd.conf這個配置 檔案和htdocs檔案夾下面的内容。如果你确實不需 要,你需要手工删除。
在 Windows的 環境下面安裝含有SSL的Apache和不含有 Apache的方法和過程一緻。
這裡關鍵說安裝以後的服務配置。
httpd.conf檔案,如果需要Apache伺服器支援SSL,這裡需要 載入幾個子產品。
去掉下面兩行之前的#符号
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so的作用是載入SSL子產品
Include conf/extra/httpd-ssl.conf 的作用是告訴Apache的SSL子產品到那裡去找配置檔案
重新啟動伺服器,測試一下看有沒有什麼問題。
顯然在重新啟動伺服器的時候報了一個錯誤,說伺服器無法正常啟動。這時候我們可以看看日志檔案了。
[Fri Aug 15 15:33:08 2008] [notice] Parent: Received restart signal -- Restarting the server.
[Fri Aug 15 15:33:08 2008] [notice] Child 740: Exit event signaled. Child process is ending.
Syntax error on line 99 of D:/Dkits/Apache2.2/conf/extra/httpd-ssl.conf:
SSLCertificateFile: file 'D:/Dkits/Apache2.2/conf/server.crt' does not exist or is empty
[Fri Aug 15 15:33:08 2008] [warn] (OS 995)The I/O operation has been aborted because of either a thread exit or an application request. : winnt_accept: Asynchronous AcceptEx failed.
[Fri Aug 15 15:33:09 2008] [notice] Child 740: Released the start mutex
[Fri Aug 15 15:33:10 2008] [notice] Child 740: All worker threads have exited.
[Fri Aug 15 15:33:10 2008] [notice] Child 740: Child process is exiting
上面說在D:/Dkits/Apache2.2/conf/server.crt路徑下找不到server.crt這個檔案。
那麼,這個檔案在那裡呢?
這個檔案需要我們用 openssl這個程式來生成的。生成這個 server.crt檔案需要2個檔案,一個是openssl.exe 另一個是openssl.cnf。
一般來說openssl.exe 在你Apache的安裝路徑下的bin檔案夾裡面,openssl.cnf在Apache安裝路徑下的conf檔案裡面。找不到?如果找不到就用 windows的查找搜尋一下了。這個時候你需要将openssl.exe和openssl.cnf放在同一個檔案夾裡面。
一般的需要将找到的openssl.cnf檔案拷貝到bin檔案裡面。
用openssl生成KEY
生成自簽名檔案
首先生成csr和pem檔案。
指令是:openssl req -config openssl.cnf -new -out server.csr -keyout server.pem
運作結果如下:
D:\Dkits\Apache2.2\bin>openssl req -config openssl.cnf -new -out server.csr -keyout server.pem
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
.........++++++
.........++++++
writing new private key to 'server.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
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]:US
State or Province Name (full name) [Some-State]:New Hampshire
Locality Name (eg, city) []:Manchester
Organization Name (eg, company) [Internet Widgits Pty Ltd]:CUIST
Organizational Unit Name (eg, section) []:IT Section
Common Name (eg, YOUR name) []:localhost
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
D:\Dkits\Apache2.2\bin>
其中有幾個地方需要注意
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
用于輸入和重複輸入密碼的,密碼長度不能小于4位
Common Name (eg, YOUR name) []:localhost
用于輸入用戶端能夠通路SSL的位址:這裡SSL伺服器是在本地運作的,是以你可以輸入localhost如果你的SSL位址運作網站主機上,那麼這裡需 要輸入例如 www.cuist.com了。
An optional company name []:留白,如果輸入将會報錯。
其他的提示輸入部分,可以輸入也可以留白,最重要的就是Common Name (eg, YOUR name) []:這個變量,關系到你的SSL服務能不能夠運作。
為Apache建立沒有密碼保護的key
下面需要為Apache建立一個沒有密碼保護的key了。
指令是openssl rsa -in server.pem -out server.key
運作結果如下
在這裡你需要輸入密碼,這個密碼是你在上一步輸入過的。如果沒有錯誤,你将會看到writing RSA key這句話後面沒有任何内容和錯誤提示。
建立X.509證書
現在需要為Apache建立X.509證書了。
指令是:openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 365
結果如下:
如果沒有錯誤,将會看到簽名已經成功,後面有簽名的詳細資訊和内容。
現在你再看看opensel.exe所在的檔案夾下面是不是多了4個檔案了,分别 是:server.pem,server.key,server.csr,server.crt
其實我們并不需要所有的這4個檔案,我一向喜歡偷懶,就把這4個檔案直接拷貝到conf檔案夾下面儲存。
重新啟動錯誤
如果重新啟動沒有錯誤,但是還是不能通路。
這時候你需要檢查日志檔案,有一種可能是443端口的沖突,如果你的機器已經安裝了IIS,那需要将IIS的web服務,FTP,SMTP服務全部關掉再 重新啟動。
如果既沒有日志輸出,也不能通路,那是因為配置檔案沒有被正确的載入,這時候你需要先在httpd.conf檔案裡面注釋掉這句話Include conf/extra/httpd-ssl.conf,然後重新啟動Apache的服務。等服務成功啟動以後,再打開這句話,再重新啟動服務。這時候你就 能看到日志的輸出了。否則不管你重新啟動多少次,Apache還是隻會載入老的httpd-ssl.conf檔案,不會重新讀取httpd- ssl.conf的。
如果在日志裡面有警告
[Fri Aug 15 16:15:10 2008] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
[Fri Aug 15 16:15:10 2008] [notice] Child 3664: Released the start mutex
[Fri Aug 15 16:15:10 2008] [warn] RSA server certificate CommonName (CN) `localhost' does NOT match server name!?
那是因為你輸入的SSL服務為localhost但是你Apache在安裝的時候服務卻不是localhost。這時候你需要改幾個地方。
httpd-ssl.conf檔案中的
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. [email protected]
#
ServerAdmin [email protected]
将ServerAdmin 變量中 [email protected]的 改成[email protected]
儲存上述兩個配置檔案後重新啟動Apache伺服器,如果沒有日志輸出,則需要先在httpd.conf檔案裡面注釋掉這句話Include conf/extra/httpd-ssl.conf,然後重新啟動Apache的服務。等服務成功啟動以後,再打開這句話,再重新啟動服務。
在輸出的日志裡面應該不會包含有任何的警告資訊了。
[Fri Aug 15 16:29:13 2008] [notice] Parent: Received restart signal -- Restarting the server.
[Fri Aug 15 16:29:13 2008] [notice] Child 3908: Exit event signaled. Child process is ending.
[Fri Aug 15 16:29:13 2008] [notice] Apache/2.2.9 (Win32) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6 configured -- resuming normal operations
[Fri Aug 15 16:29:13 2008] [notice] Server built: Jun 13 2008 04:04:59
[Fri Aug 15 16:29:13 2008] [notice] Parent: Created child process 2976
[Fri Aug 15 16:29:14 2008] [notice] Child 3908: Released the start mutex
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Child process is running
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Acquired the start mutex.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting 64 worker threads.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting thread to listen on port 443.
[Fri Aug 15 16:29:14 2008] [notice] Child 2976: Starting thread to listen on port 80.
[Fri Aug 15 16:29:15 2008] [notice] Child 3908: All worker threads have exited.
[Fri Aug 15 16:29:15 2008] [notice] Child 3908: Child process is exiting
# General setup for the virtual host
DocumentRoot "D:/Dkits/Apache2.2/htdocs"
ServerName CUIST_PC02.rochester.cuist.local:443
ServerAdmin [email protected]
ErrorLog "D:/Dkits/Apache2.2/logs/error.log"
TransferLog "D:/Dkits/Apache2.2/logs/access.log"
将ServerName CUIST_PC02.rochester.cuist.local:443變量中的 CUIST_PC02.rochester.cuist.local:443改成localhost:443
将ServerAdmin 變量中 [email protected]的 改成[email protected]
httpd.conf檔案中的
下載下傳 (85.46 KB)
2009-10-30 08:28
HTTP服務啟動在80端口,SSL服務啟動在443端口。
驗證
在HTTP能正常通路的位址下面加上S變成https。
如果http://localhost/phpMyAdmin/index.php變化成https://localhost/phpMyAdmin /index.php
這時候應該能夠看到一個證書警告的資訊
下載下傳 (283.82 KB)
2009-10-30 08:33
同意這個證書,看看是不是能夠看到web頁面了呀,如果能,則說明SSL已經被正确的配置到Apache服務裡面來了。可以輕松一下了喔。。 轉自: http://apps.hi.baidu.com/share/detail/9247188