https://my.oschina.net/xpbug/blog/197454php
apache httpd 2.4(windows)css
perl 5 (windows)html
openssl (windows)java
由於手上沒有linux的空餘機器,因此一切操做都是在windows平臺上。安裝以上三個軟件的win版,略。linux
首先用httpd搭建一個簡單的網站。在apache的目錄下,找到httpd.conf文件,打開文件,找到下面的內容,並把註釋去掉:nginx
# Virtual hosts Include conf/extra/httpd-vhosts.conf
找到httpd-vhosts.conf文件,打開,並向其中添加一個虛擬網站shell
<VirtualHost *:80> ServerAdmin joey DocumentRoot "D:/www/test0" ServerName www.test0.com ErrorLog "logs/errlog" CustomLog "logs/accesslog" common <Directory "D:/www/test0"> Order allow,deny Allow from all </Directory> </VirtualHost>
在網站目錄下面建立一個index頁面, index.htmlapache
<html> <body>test0</body> </html>
重啓httpd,訪問網站http://www.test0.com, 能夠看到test0頁面。(注意,若是www.test0.com沒法加入DNS,則能夠修改本地的hosts文件)。swift
SSL中存在三種證書,頂級證書,服務器證書和客戶端證書。windows
頂級證書是權威證書頒發機構所持有的證書,權威機構使用頂級證書給服務器證書或客戶端證書進行簽名。
服務器證書是咱們最多見的,訪問多有https的網站,都會收到一個服務器證書,若是證書是有有名的權威機構頒發,則瀏覽器就會幫咱們處理證書。若是證書是由不知名機構頒發,瀏覽器會跳出窗口,問咱們是否信任此證書。
客戶端證書常見於網銀。像招商銀行的客戶端,可使用電子證書。之因此存在客戶端證書,緣由是服務器想驗證客戶的合法性。這時候,信任是雙向的。
通常互聯網上,只須要服務器證書,信任是單向的,服務器並不對客戶作驗證。
安裝完openssl之後,其目錄存在於C:\OpenSSL-Win32. 如今讓咱們來生成各類證書。
打開cmd命令臺,在運行openssl的命令以前,先設置環境變量
>set OPENSSL_CONF=c:\openssl-win32\bin\openssl.cfg
生成頂級證書。這部分應該是有權威機構作的,這裏我冒充一下權威機構。
>CA.pl -newca
在/demoCA/目錄下會生成CA的必須文件。這其中包含頂級證書。
服務器商須要爲本身生成公鑰密鑰,並製做一個證書申請。這裏仍是我來冒充一下。
>openssl.exe genrsa -des3 -out server.key 1024 >openssl.exe req -new -key server.key -out server.csr
注意,當遇到下面一行的時候,必定要填寫網站的域名,好比今天的例子www.test0.com.
服務商把證書申請server.csr發送給權威機構,權威機構進行簽名。將server.csr重命名爲newreq.pem,而後執行下面命令
>CA.pl -sign
生成的newcert.pem就是證書,將newcert.pem重命名爲server.crt,而後發還給服務商。
生成客戶端證書,這部分並不在本實驗中,能夠忽略,但我把要執行的命令列在這裏,以便於之後查找。
>openssl.exe genrsa -des3 -out client.key 1024 >openssl.exe req -new -key client.key -out client.csr >openssl.exe ca -in client.csr -out client.crt #生成客戶端可安裝文件。 >openssl.exe pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.pfx
上面的步驟中,將得到的server.key和server.crt複製出來,待會用。
在win32上,apache不支持加密的private key,因此還須要額外步驟,去除加密。請看最後面的部分。
修改httpd.conf文件,將其中兩行的註釋去掉
LoadModule ssl_module modules/mod_ssl.so
# Secure (SSL/TLS) connections Include conf/extra/httpd-ssl.conf
打開httpd-ssl.conf文件,進行編輯
NameVirtualHost *:443 <VirtualHost *:443> ServerAdmin joey DocumentRoot "D:/www/test0" ServerName www.test0.com:443 ErrorLog "logs/errlog" CustomLog "logs/accesslog" common SSLEngine on SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/server.crt" SSLCertificateKeyFile "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/server.key" <Directory "D:/www/test0"> Order allow,deny Allow from all </Directory> </VirtualHost>
注意,SSLCertificateFile和SSLCertificateKeyFile必須指向以前咱們生成的key和證書。
沒法重啓httpd,並在error.log中發現這麼一句話:
SSLPassPhraseDialog builtin is not supported on Win32
緣由是由於Win32不支持SSLPassPhraseDialog命令,咱們須要把此命令個註釋掉,並須要把server.key的PassPhrase也給去掉。步驟以下
重命名server.key爲server.key.org
運行命令 >openssl rsa -in server.key.org -out server.key
將產生的new key替換到原來的位置。
編輯httpd-ssl.conf,把 #SSLPassPhraseDialog builtin註釋掉。
再重啓一下httpd. 還有錯誤,error.log中有這麼一句話:
Syntax error on line 62 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/extra/httpd-ssl.conf:
SSLSessionCache: Invalid argument: size has to be >= 8192 bytes
緣由是命令吧(X86)給當作86來解析了,須要作下修改
#修改前 SSLSessionCache "shmcb:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)" #修改後 SSLSessionCache "shmcb:C:/PROGRA\~2/Apache Software Foundation/Apache2.2/logs/ssl_scache(512000)"
再次重啓,成功。
在瀏覽器中輸入網址https://www.test0.com, 瀏覽器會詢問你是否信任當前證書。由於這個證書不是權威機構發放的。選擇信任。咱們能夠查看證書,證書裏面的簽發機構是我。
下一步,將使用tomcat搭建集羣,使用apache作負載平衡。http://my.oschina.net/xpbug/blog/197680
接着,會給tomcat製做登陸頁面。而後只保留登陸頁面的https鏈接,其它頁面使用http.
而後,會開啓tomcat認證和受權。
接着,會搭建第二個tomcat網站,並開啓兩個網站之間的SSO。
最後,會着手性能優化,如何增長cache。