2013年5月19日 星期日

Apache


Apache
安裝 Apache
#yum -y install httpd
設置 Apache 隨系統自動啟動
# chkconfig httpd on
設定自動啟動
# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
啟動 Apache 服務
# /etc/rc.d/init.d/httpd start
開啟防火牆
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
VirtualHost
設定使用VirtualHost ,修改httpd.conf
LoadModule jk_module modules/mod_jk.so 如果要使用JKMount請加入
include conf/vhost.conf
維護網頁,修改httpd.conf
<VirtualHost *:80>
DocumentRoot "/var/www/antepoker"
include conf/maintain   //加入
</VirtualHost>
#vim /etc/httpd/conf/maintain  //要開啟maintain 時,把#去掉
  #RewriteEngine On
  #RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  #RewriteCond %{REQUEST_FILENAME} !/maintenance.html
  #RewriteRule ^.*$    /maintenance.html [L]
#vim /var/www/antepoker/ maintenance.html
<html>
<center>
<font size=7 color=black>Ezybid2u<br></font>
<font size=7 color=black>Sorry , we are under routine maintenance now. Please come back later.<br></font>
</center>
</html>

設定
Include conf/mod_jk.conf
NameVirtualHost *:80
<VirtualHost *:80>
 ServerName abc.com
 DocumentRoot "/var/www/antepoker"
 JKMount /antepoker/* antepoker
 JKMount /antepoker antepoker
</VirtualHost>

進階使用
設定使用1234 連結Tomcat connect
Include conf/mod_jk.conf
Listen 1234
NameVirtualHost 192.168.2.150:1234
<VirtualHost 192.168.2.150:1234>
 ServerName abc.com
 DocumentRoot "/var/www/antepoker"
 JKMount /antepoker/* antepoker
 JKMount /antepoker antepoker
</VirtualHost>
並使用iptables 指令IP轉Port
/sbin/iptables -A INPUT -p tcp -s 192.168.2.110 --dport 1234 -j ACCEPT
iptables -A PREROUTING -t nat -s 192.168.2.110 -p tcp --dport 80 -j REDIRECT --to-port 1234

Maintain Page
<html>
<center>
<font size=7 color=black>Ezybid2u<br></font>
<font size=2 color=black><br></font>
<img src="../regular_septic_maintenance.jpg" width=300 hight=300 align=center>
</center>
</html>

CBand
設定Cache and Gzip
偵測mod_cband 設定
下載:http://rpm.pbone.net/index.php3/stat/4/idpl/6572994/dir/centos_5/com/mod_cband-0.9.7.5-2.el5.kb.x86_64.rpm.html
安裝 #rpm -ivh mod_cband-0.9.7.5-2.el5.kb.x86_64.rpm
備份/etc/httpd/conf.d/mod_cband.conf
修改/etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerName xxx.xxx.xxx #這邊是你虛擬主機的功能變數名稱
DocumentRoot /var/www/xxxxxxxx #網站根目錄
<IfModule mod_cband.c> #判斷如果模組存在
CBandSpeed 512 200 200 #限制最大的速度 512bps 及每秒最多併發200個請求最多同時併發200個連接
CBandRemoteSpeed 512 200 200 #限制遠端連接最大的速度 512bps 及每秒最多併發200個請求最多同時併發200個連接
CBandPeriod 4W #即時監測日誌每多久歸0 4W就是4周
<Location /cband-status> #如果要開啟即時監測設定虛擬目錄 可用 http://xxx.xxx.xxx/cband-status 來監看
SetHandler cband-status #監測域站
Order allow,deny
Allow from 192.168.2.0/24
</Location>
</IfModule>
</VirtualHost>
# <Location /cband-status-me> #如果要開啟即時監測設定虛擬目錄 可用 http://xxx.xxx.xxx/cband-status-me 來監看
#SetHandler cband-status-me #只監測本域站
#SetHandler cband-status #全域監測
#</Location>
配置mod_cband
打開Apache設定檔,在設定檔末尾加入如下內容,如果有虛擬主機,可將其加入到虛擬主機配置內容中
#vi /usr/local/apache/conf/httpd.conf
CBandLimit 100M //限制本節點總訪問頻寬為100Mb
CBandSpeed 1024 10 30 //限制本節點的最大連線速度為1024kb,最大併發處理10個請求和30個連接數
CBandRemoteSpeed 20kb/s 5 3 //限制一個用戶最大連接本節點為20kb,最大5個併發和3個連接數
CBandPeriod 4W //多久後對本節點限制進行重設,W=week
SetHandler cband-status //開啟mod_cband全域檢測功能,可通過http://servername/cband-status 進行查看
SetHandler cband-status-me //開啟mod_cband單一檢測功能,可通過http://servername/cband-status-me進行查看
三、測試
輸入http://伺服器IP/cband-status 可以查看到伺服器每個網站當前的流量和訪問情況附:matrix現在伺服器用的腳本
CBandUserLimit 10Gi
CBandUserSpeed 100kb/s 20 20
CBandUserExceededSpeed 20kb/s 10 10
CBandUserPeriod 4W

CBandUserLimit 100Gi
CBandUserSpeed 100kb/s 30 30
CBandUserExceededSpeed 30kb/s 10 10
CBandUserPeriod 4W
低端配置
CBandLimit 10Gi
CBandSpeed 1024 50 50
CBandRemoteSpeed 50kb/s 30 30
CBandExceededSpeed 20kb/s 10 10
CBandPeriod 2W
高端配置
CBandLimit 100Gi
CBandSpeed 1024 5000 10000
CBandRemoteSpeed 100kb/s 30 30
CBandExceededSpeed 20kb/s 10 10
CBandPeriod 2W
#測試用的
CBandLimit 10M
CBandSpeed 1024 10 10
CBandRemoteSpeed 10kb/s 3 3
CBandExceededURL http://www.0379danbao.com/404.html
#CBandExceededSpeed 10kb/s 1 1
CBandPeriod 2W
查看url:/IP/cband-status




Cache 設定
當我們的網站的 loading 越來越大的情況下, 我們可以用以下方法來提升網站的效率
1. 啟用壓縮來降低頻寬的使用量
2. 設定快取讓 apache 執行更為順暢.
以下就簡單的分享一下 cache 的設定 !! 首先在 httpd.cont 確認是否有載入以下兩個模組.
LoadModule cache_module modules/mod_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
確認後呢 , 在 httpd.conf 裡加上以下設定 !!
<IfModule mod_mem_cache.c>
CacheEnable mem /
CacheDirLevels 2
CacheDirLength 2
CacheMaxFileSize 500000
CacheMinFileSize 1024
MCacheSize 350000
MCacheMaxObjectCount 5000
MCacheMaxObjectSize 3200000
MCacheMinObjectSize 5000
</IfModule>
這樣就可以簡單的啟用快取囉 !!


啟動apache2的gzip
Web伺服器處理HTTP壓縮的過程如下:
    1. Web伺服器接收到流覽器的HTTP請求後,檢查流覽器是否支援HTTP壓縮(Accept-Encoding 資訊)。
    2. 如果流覽器支援HTTP壓縮,Web伺服器檢查請求檔的尾碼名。
    3. 如果請求檔是HTML、CSS等靜態檔,Web伺服器到壓縮緩衝目錄中檢查是否已經存在請求檔的最新壓縮檔。
    4. 如果請求檔的壓縮檔不存在,Web伺服器向流覽器返回未壓縮的請求檔,並在壓縮緩衝目錄中存放請求檔的壓縮檔。
    5. 如果請求檔的最新壓縮檔已經存在,則直接返回請求檔的壓縮檔。
    6. 如果請求檔是動態檔,Web伺服器動態壓縮內容並返回流覽器,壓縮內容
不存放到壓縮緩存目錄中。
1.檢查模組
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
打開httpd.conf後,先將上面兩行配置前面的#號去掉,這樣apache就會啟用這兩個模組,其中mod_deflate是壓縮模組,就是對要傳輸到用戶端的代碼進行gzip壓縮;mod_headers模組的作用是告訴流覽器頁面使用了gzip壓縮,如果不開啟mod_headers那麼流覽器就會對gzip壓縮過的頁面進行下載,而無法正常顯示。
2.設定
開啟了壓縮功能默認:
<ifmodule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-
php
AddOutputFilter DEFLATE js 
css
</ifmodule>

項目
說明:
DeflateCompressionLevel 9
是指壓縮程度的等級,從1到9,9是最高等級。據瞭解,這樣做最高可以減少8成大小的傳輸量(看檔案內容而定),最少也能夠節省一半,預設可以採用6 這個數值,以維持耗用處理器效能與網頁壓縮品質的平衡。
SetOutputFilter DEFLATE
必須的,就像一個開關一樣,告訴apache對傳輸到流覽器的內容進行壓縮
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
設置不對尾碼gif,jpg,jpeg,png的圖片檔進行壓縮
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
同上,就是設置不對exe,tgz,gz。。。的檔進行壓縮
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
設置對檔是文本的內容進行壓縮,例如text/html  text/css  text/plain等
AddOutputFilterByType DEFLATE text/*

AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
這段代碼你只需要瞭解application/javascript application/x-javascript這段就可以了,這段的意思是對javascript檔進行壓縮
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
這段是告訴apache對php類型的檔進行壓縮
BrowserMatch ^Mozilla/4 gzip-only-text/html
Netscape 4.x有一些問題,所以只壓縮檔類型是text/html的
BrowserMatch ^Mozilla/4.0[678] no-gzip
Netscape 4.06-4.08 有更多的問題,所以不開啟壓縮
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
IE流覽器會偽裝成 Netscape ,但是事實上它沒有問題

</IfModule>
<IfModule mod_mem_cache.c>
 CacheEnable mem /
 CacheDirLevels 2
 CacheDirLength 2
 CacheMaxFileSize 500000
 CacheMinFileSize 1024
 MCacheSize 350000
 MCacheMaxObjectCount 5000
 MCacheMaxObjectSize 3200000
 MCacheMinObjectSize 5000
</IfModule>
<ifmodule mod_deflate.c>
 DeflateCompressionLevel 9
 AddOutputFilterByType DEFLATE text/html text/plain text/xml
 BrowserMatch ^Mozilla/4 gzip-only-text/html
 BrowserMatch ^Mozilla/4\.0[678] no-gzip
 BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
 Header append Vary User-Agent env=!dont-vary
</ifmodule>


<VirtualHost *:80>
ServerName goodbuystall.com
ServerAlias www.goodbuystall.com
DocumentRoot "/usr/local/apache/htdocs/goodbuystall"


<Directory "/usr/local/apache/htdocs/goodbuystall">
   Options FollowSymLinks
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>


#Part below function to mod_jk mounting to tomcat or jboss ajp port
JKMount / goodbuystall
JKMount /* goodbuystall


#Part below function to compress the content of the webpage
<Location />
   SetOutputFilter DEFLATE
   SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
   SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
   SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
   AddOutputFilterByType DEFLATE text/plain text/html text/css text/xml
   AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
   AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
   AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp application/xhtml+xml application/xml application/rss+xml application/atom_xml application/x-httpd-eruby
   AddOutputFilterByType DEFLATE image/svg+xml
   BrowserMatch ^Mozilla/4 gzip-only-text/html
   BrowserMatch ^Mozilla/4.0[678] no-gzip
   BrowserMatch bMSIE !no-gzip !gzip-only-text/html
</Location>


#Part below configuration is a 2 line configuration, Start with ErrorLog #and CustomLog. It function to have a separate log for every virtual #host and auto rotate the log every day.
ErrorLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/goodbuystall-error_log_%Y%m%d 86400"
CustomLog "|/usr/local/apache/bin/rotatelogs /usr/local/apache/logs/goodbuystall-access_log_%Y%m%d 86400" combined


</VirtualHost>
Test page
http://www.port80software.com/products/httpzip/

Apache2 載入 Expires 的模組(mod_expires) 與 設定
設定 圖片 / CSS / Javascript 等靜態檔案的過期時間, 可以讓網頁下次 loading 的速度更快(直接從瀏覽器的 cache 拉), 也可以節省 頻寬 和 Apache 吐這些檔案所耗的資源.
哪些檔案要加入 Expire header 的, 做如下述的設定:

Apache 的設定檔加入
Vi /etc/httpd/conf/httpd.conf
<IfModule mod_expires.c>
ExpiresActive On
#ExpiresByType application/javascript "access plus 1 week"
#ExpiresByType application/x-javascript "access plus 1 week"
#ExpiresByType text/javascript "access plus 1 week"
#ExpiresByType text/css "access plus 1 day"
#ExpiresByType text/plain "access plus 1 hours"
#ExpiresByType text/html A900
#ExpiresByType text/xml A14400
ExpiresByType image/gif "access plus 1 day"
ExpiresByType image/jpg "access plus 1 day"
ExpiresByType image/jpeg "access plus 1 day"
ExpiresByType image/png "access plus 1 day"
ExpiresByType image/bmp "access plus 1 day"
#ExpiresByType application/x-shockwave-flash A3600
#special MIME type for icons - see #http://www.iana.org/assignments/media-types/image/vnd.microsoft.icon
AddType image/vnd.microsoft.icon .ico
# now we have icon MIME type, we can use it
# my favicon doesn't change much
ExpiresByType image/vnd.microsoft.icon "access plus 3 months"
</IfModule>


Apache Rewrite 模組
http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_rewrite.html
RewriteBase 指令 設置目錄級重寫的基準URL
RewriteCond 指令 定義重寫發生的條件
RewriteEngine 指令 打開或關閉運行時的重寫引擎
RewriteRule 指令 為重寫引擎定義重寫規則
RewriteLog 指令 設置重寫引擎日誌的檔案名
RewriteLogLevel 指令 設置重寫日誌的詳細程度
文本
.           任意一個單字元
 [chars]     字元類: "chars"中的任意一個字元
 [^chars]    字元類: 不在"chars"中的字元
 text1|text2 選擇: text1 或 text2
量詞
 ?           前面的字元出現 0 或 1 次
 *           前面的字元出現 0 或 N 次(N > 0)
 +           前面的字元出現 1 或 N 次(N > 1)
分組
 (text)      text 組
             (常用於設置一個選擇的邊界,或用於生成後引用:
              在RewriteRule中可以用 $N 引用第N個分組)
 ^           錨定到行首
 $           錨定到行尾
轉義
 \c          對給定的字元c進行轉義
             (比如對".[]()"進行轉義,等等)

<Virtualhost *:80>
 ServerName 61.67.246.79
 DocumentRoot "/var/www/protect"
 RewriteEngine on
 RewriteRule ^/(.*) /index.html [L]
 RewriteLog "/var/log/httpd/rewrite.log"
 RewriteLogLevel 3
</Virtualhost>

  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
  RewriteCond %{REQUEST_FILENAME} !/maintenance.html
  RewriteRule ^.*$ /maintenance.html [L]


Apache網站伺服器安全性設定
現今大部分的網站伺服器均採用開源軟體Apache來服務,許多市售書籍也會針對Apache的主設定檔(apache.conf or httpd.conf)作詳細的介紹,可是關於Apache的安全性調整卻很少提及,而這往往是系統漏洞的開端。
Crackers要發動網站攻擊前,會先進行一個標準動作:footprinting,用意在收集以下資訊,以勾繪出一個網站可能漏洞的輪廓:
作業系統名稱及版本
網站伺服器名稱及版本
對外開放那些port
確認網域、IP位址、DNS查詢
Web資料收集等等
如何針對一個網站伺服器做footprint呢?最簡單的方法是送出一個HTTP要求,網站伺服器則會傳回一個HTTP回應,其內的標頭(header)資訊便包含了網站伺服器名稱、版本、作業系統名稱及相關的模組版本,如下所示:
1.關閉Apache伺服器及相關模組版本
在apache.conf 或 httpd.conf 最下方加入
ServerTokens ProductOnly (告知Apache在回傳標頭資訊時,只要標示產品名稱"Apache"即可)
ServerSignature Off (告知Apache在產生錯誤頁面或其他訊息時,不顯示Apache版本)
TraceEnable Off (用途為除錯,預設開啟,建議關閉)
Vim /etc/httpd/conf/httpd.conf
ServerTokens ProductOnly
ServerSignature Off
TraceEnable Off   //自己家

2.關閉PHP版本
在php.ini 中尋找 expose_php,預設是開啟(On),修正為Off
expose_php = Off (告知Apache不顯示PHP相關訊息)
再測試一下HTTP要求,可以發現回應的HTTP標頭變得簡潔多了,也不會顯示重要的系統資訊

以上的測試方法皆使用 HTTP/HTTPS Header Check 網頁小工具,只要輸入欲查詢的網址,可以幫您了解此網站伺服器的HTTP回應標頭是否含有重要資訊,有興趣的朋友們可以試試看 :)

修改前
HTTP/1.1 200 OK =>
Date => Wed, 13 Mar 2013 08:10:32 GMT
Server => Apache/2.2.3 (CentOS)
Last-Modified => Mon, 21 Jan 2013 11:46:56 GMT
ETag => "d90108-53-4d3cb049c0c00"
Accept-Ranges => bytes
Content-Length => 83
Vary => Accept-Encoding,User-Agent
Connection => close
Content-Type => text/html; charset=UTF-8
修改後
HTTP/1.1 200 OK =>
Date => Wed, 13 Mar 2013 08:55:32 GMT
Server => Apache
Last-Modified => Wed, 23 Jan 2013 08:33:06 GMT
ETag => "d90107-ba-4d3f08b171480"
Accept-Ranges => bytes
Content-Length => 186
Cache-Control => max-age=900
Expires => Wed, 13 Mar 2013 09:10:32 GMT
Vary => Accept-Encoding,User-Agent
Connection => close
Content-Type => text/html; charset=UTF-8


保護virtual host 設定使用IP進入導向400錯誤(有問題)
<Virtualhost *:80>
 ServerName 61.67.246.79
 DocumentRoot "/var/www/protect"
 RewriteEngine on
 RewriteRule ^/(.*) /index.html [L]
 RewriteLog "/var/log/httpd/rewrite.log"
 RewriteLogLevel 3
</Virtualhost>
Vim /var/www/protect/index.html
<html>
<font size=6 color=black>Bad Request</font>
<font size=2 color=black><br>Your browser sent a request that this server could not understand.</font>
</html>


SSL
#yum -y install mod_ssl
/etc/httpd/conf.d/ssl.conf:mode_ssl 提供的 Apache 設定檔;
/etc/pki/tls/private/localhost.key:系統私鑰檔,可以用來製作憑證的!
/etc/pki/tls/certs/localhost.crt:就是加密過的憑證檔!(signed certificate)
預設已開啟可以測試看看。
建立憑證檔
預設的憑證雖然已經可以讓你順利的使用 https 了,不過,憑證的有效日僅有 1 年而已~實在討厭~ 所以,我們還是得要自製憑證才行~這個憑證的製作僅是私有 WWW 網站的用途,並沒有要拿去 CA 註冊喔! 那麼自製憑證需要什麼步驟呢?基本上需要的流程是:

先建立一把 private key 預備提供給 SSL 憑證簽章要求所用;
最後建立 SSL 憑證 (test certificates)。
那麼建立憑證有沒有很困難呢?沒有啦!因為 CentOS 6.x 已經幫我們寫好了 Makefile 了!你先到 /etc/pki/tls/certs 這個目錄下,然後直接輸入 make 這個指令,就能夠看到所有可行的目標動作!我們就可以很快速的建置好憑證喔! 不過,因為預設的私鑰檔需要加上密碼才能夠進行建立,所以我們還得要額外進行一下動作就是了。好! 現在假設我們要建立的是名為 vbird 的憑證!那麼底下流程中,所有的關鍵字就是 vbird!簡單流程如下所示:
# 1. 先到 /etc/pki/tls/certs 去建立一把給 Apache 使用的私鑰檔案:
[root@www ~]# cd /etc/pki/tls/certs
[root@www certs]# make vbird.key
umask 77 ; /usr/bin/openssl genrsa -aes128 2048 > vbird.key  <==其實是這個指令
Generating RSA private key, 2048 bit long modulus
.................................................................+++
...............................+++
e is 65537 (0x10001)
Enter pass phrase:  <==這裡輸入這把私鑰的密碼,需要多於四個字元!
Verifying - Enter pass phrase:  <==再一次!


# 2. 將剛剛建立的檔案中,裡面的密碼取消掉!不要有密碼存在啦!
[root@www certs]# mv vbird.key vbird.key.raw
[root@www certs]# openssl rsa -in vbird.key.raw -out vbird.key
Enter pass phrase for vbird.key.raw: <==輸入剛剛的密碼啦!
writing RSA key
[root@www certs]# rm -f vbird.key.raw  <==舊的金鑰檔移除
[root@www certs]# chmod 400 vbird.key  <==權限一定是 400 才行!


# 3. 建置所需要的最終憑證檔!
[root@www certs]# make vbird.crt SERIAL=2011080801
umask 77 ; /usr/bin/openssl req -utf8 -new -key vbird.key -x509 -days 365
-out vbird.crt -set_serial 2011080801  <==可以加入日期序號
You are about to be asked to enter information that will be incorporated
into your certificate request.
-----
Country Name (2 letter code) [XX]:TW
State or Province Name (full name) []:Taiwan
Locality Name (eg, city) [Default City]:Tainan
Organization Name (eg, company) [Default Company Ltd]:KSU
Organizational Unit Name (eg, section) []:DIC
Common Name (eg, your name or your server's hostname) []:www.centos.vbird
Email Address []:vbird@www.centos.vbird


[root@www certs]# ll vbird*
-rw-------. 1 root root 1419 2011-08-08 15:24 vbird.crt  <==最終憑證檔!
-r--------. 1 root root 1679 2011-08-08 15:22 vbird.key  <==系統私鑰檔
這樣就建立好憑證檔了!接下來就是得要去處理 ssl.conf 這個設定內容喔!另外,這把憑證依舊只能使用 1 年!如果你想要建立十年的憑證,那就得要修改一下 Makefile 裡面的內容,將 365 改成 3650 即可!

修改 ssl.conf 的內容,使用自製憑證
修改 ssl.conf 的內容也是很簡單!只要修改兩個地方,亦即是檔案檔名的地方即可!
[root@www ~]# vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/vbird.crt    <==約在 105 行
SSLCertificateKeyFile /etc/pki/tls/certs/vbird.key <==約在 112 行

[root@www ~]# /etc/init.d/httpd restart

然後再以瀏覽器去瀏覽 https:// 的網址,就能夠查閱到剛剛建立的憑證資料。不過,因為我們之前已經有瀏覽過預設的憑證, 所以網頁以及憑證都有被快取過!因此,你可能得需要到瀏覽器的隱私保護的地方,將記錄的憑證刪除,並且將網頁快取刪除, 這樣才能夠看到最終如下的正確憑證資料喔


將加密首頁與非加密首頁分離
或許你已經發現一個無俚頭的地方,就是我的 http:// 以及 https:// 首頁是一模一樣的嘛!那麼我的讀者幹嘛沒事找事幹, 肯定不會使用 https 的嘛!那怎辦?怎麼強制使用者使用 https:// 來查閱我的重要資料?很簡單啊! 透過虛擬主機就好了啊!因為 SSL 模組也是預設提供了這個功能的嘛!修改會不會很麻煩呢?不會啦! 你只要將 http 及 https 的首頁分離即可!我們這麼假設好了:

一般明碼傳輸的網頁首頁不要變更;
https:// 的首頁放置到 /var/www/https/ 目錄下。
所以我們得先要設定 /var/www/https 目錄才行!然後,只要修改 ssl.conf 檔案內容即可!整個過程可以這樣處理:
1. 處理目錄與預設的首頁 index.html 檔案:
[root@www ~]# mkdir /var/www/https
[root@www ~]# echo "This is https' home" > /var/www/https/index.html

# 2. 開始處理 ssl.conf 的內容囉!
[root@www ~]# vim /etc/httpd/conf.d/ssl.conf
Listen 443                      <==預設的監聽埠口!不建議修改!
<VirtualHost _default_:443>     <==就是虛擬主機的設定囉!
DocumentRoot "/var/www/https"   <==約84行,拿掉註解改掉目錄名稱
ServerName *:443                <==拿掉註解,並將主機名稱設定為 *
SSLEngine on                    <==有支援 SSL 的意思!
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/vbird.crt
SSLCertificateKeyFile /etc/pki/tls/certs/vbird.key
</VirtualHost>

[root@www ~]# /etc/init.d/httpd restart

大部分都使用預設值,就是 DocumentRoot 以及 ServerName 需要留意就是了。如此一來,我們就將 https, http 兩個完整的分開,你的重要資料需要加密的,終於有個可靠的地方擺放囉!^_^


沒有留言:

張貼留言