天天看點

Web服務(三)httpd參數配置以及編譯安裝

一、參數配置

13、https協定的實作

SSL握手要完成的工作:

   交換協定版本号

   選擇雙方都支援的加密方式

   對兩端實作身份驗證

   密鑰交換

https是二進制格式的協定,監聽與tcp:443端口。SSL會話是基于IP位址進行;不支援在基于FQDN的虛拟主機上實作。

下面直接來配置https:

CA這裡直接使用的一台機器當CA和用戶端;

建立CA和用戶端證書簽署

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<code>#建立CA;詳細過程就不貼了;以下是步驟</code>

<code>[Linux85]</code><code>#cd /etc/pki/CA/</code>

<code>[Linux85]</code><code>#(umask 077;openssl genrsa -out private/cakey.pem 2048)</code>

<code>[Linux85]</code><code>#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365</code>

<code>[Linux85]</code><code>#touch index.txt serial crlnumber</code>

<code>[Linux85]</code><code>#echo 00 &gt; serial</code>

<code>                             </code> 

<code>#生成用戶端證書以及CA簽署;CA與用戶端都是同一台機器;也可以分為兩台</code>

<code>[Linux85]</code><code>#mkdir /etc/httpd/ssl</code>

<code>[Linux85]</code><code>#cd /etc/httpd/ssl</code>

<code>[Linux85]</code><code>#(umake 077;openssl genrsa -out httpd.key 1024)</code>

<code>[Linux85]</code><code>#openssl req -new -key httpd.key -out httpd.csr</code>

<code>[Linux85]</code><code>#openssl ca -in httpd.csr -out httpd.crt -days 365</code>

<code>                          </code> 

<code>#結束後把CA憑證安裝到windows中</code>

安裝mod_ssl子產品和更改主配置檔案實作支援ssl協定:

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

<code>[Linux85]</code><code>#yum -y install mod_ssl</code>

<code>[Linux85]</code><code>#rpm -ql mod_ssl</code>

<code>/</code><code>etc</code><code>/</code><code>httpd</code><code>/</code><code>conf.d</code><code>/</code><code>ssl.conf</code>

<code>/</code><code>usr</code><code>/</code><code>lib64</code><code>/</code><code>httpd</code><code>/</code><code>modules</code><code>/</code><code>mod_ssl.so</code>

<code>/</code><code>var</code><code>/</code><code>cache</code><code>/</code><code>mod_ssl</code>

<code>/</code><code>var</code><code>/</code><code>cache</code><code>/</code><code>mod_ssl</code><code>/</code><code>scache.</code><code>dir</code>

<code>/</code><code>var</code><code>/</code><code>cache</code><code>/</code><code>mod_ssl</code><code>/</code><code>scache.pag</code>

<code>/</code><code>var</code><code>/</code><code>cache</code><code>/</code><code>mod_ssl</code><code>/</code><code>scache.sem</code>

<code>[Linux85]</code><code>#</code>

<code>                                                                                                                                                                                                                                                             </code> 

<code>#配置</code>

<code>[Linux85]</code><code>#vim ssl.conf</code>

<code>#定位ServerName;開啟下面兩項</code>

<code># General setup for the virtual host, inherited from global configuration</code>

<code>DocumentRoot </code><code>"/var/www/html"</code>

<code>ServerName www.soul.org:</code><code>443</code>

<code>#下面兩項關于密鑰和證書檔案的路徑</code>

<code>#   Server Certificate:</code>

<code># Point SSLCertificateFile at a PEM encoded certificate.  If</code>

<code># the certificate is encrypted, then you will be prompted for a</code>

<code># pass phrase.  Note that a kill -HUP will prompt again.  A new</code>

<code># certificate can be generated using the genkey(1) command.</code>

<code>SSLCertificateFile </code><code>/</code><code>etc</code><code>/</code><code>httpd</code><code>/</code><code>ssl</code><code>/</code><code>httpd.crt</code>

<code>#   Server Private Key:</code>

<code>#   If the key is not combined with the certificate, use this</code>

<code>#   directive to point at the key file.  Keep in mind that if</code>

<code>#   you've both a RSA and a DSA private key you can configure</code>

<code>#   both in parallel (to also allow the use of DSA ciphers, etc.)</code>

<code>SSLCertificateKeyFile </code><code>/</code><code>etc</code><code>/</code><code>httpd</code><code>/</code><code>ssl</code><code>/</code><code>httpd.key</code>

<code>                                                                                                                                                                                                                                                        </code> 

<code>[Linux85]</code><code>#service httpd start</code>

<code>[Linux85]</code><code>#ss -tunl | grep 443</code>

<code>tcp    LISTEN     </code><code>0</code>      <code>128</code>                   <code>:::</code><code>443</code>                  <code>:::</code><code>*</code>  

<code>#檢視443端口以正常啟動</code>

提供首頁檔案

<code>[Linux85]</code><code>#vim /var/www/html/index.html</code>

<code>This </code><code>is</code> <code>https test page!</code>

<code>#</code>

<code>把CA憑證安裝至windows中</code>

<a href="http://s3.51cto.com/wyfs02/M00/23/B6/wKioL1M_r3GTdyySAAF5NvVNiB4526.jpg" target="_blank"></a>

測試通路正常;https協定正常使用。

14、配置httpd的status頁面

<code>[Linux85]</code><code>#httpd -M | grep status</code>

<code>#下述這個子產品如存在即可配置</code>

<code> </code><code>status_module (shared)</code>

<code>Syntax OK</code>

<code>                                                                                                                                                                                               </code> 

<code>[Linux85]</code><code>#vim /etc/httpd/conf/httpd.conf</code>

<code>#定位status;找到如下項開啟</code>

<code># Allow server status reports generated by mod_status,</code>

<code># with the URL of http://servername/server-status</code>

<code># Change the ".example.com" to match your domain to enable.</code>

<code>&lt;Location </code><code>/</code><code>server</code><code>-</code><code>status&gt;</code>

<code>    </code><code>SetHandler server</code><code>-</code><code>status</code>

<code>    </code><code>AuthType    Basic            </code><code>#為了確定安裝;這裡做了認證</code>

<code>    </code><code>AuthName    </code><code>"server status"</code> 

<code>    </code><code>AuthUserFile </code><code>"/etc/httpd/conf/.htpasswd"</code>

<code>    </code><code>Require valid</code><code>-</code><code>user</code>

<code>    </code><code>Order deny,allow</code>

<code>    </code><code>Deny </code><code>from</code> <code>all</code>

<code>    </code><code>Allow </code><code>from</code> <code>172.16</code><code>.</code><code>254.28</code>    <code>#限定隻能改IP通路該頁面</code>

<code>&lt;</code><code>/</code><code>Location&gt;</code>

<a href="http://s3.51cto.com/wyfs02/M00/23/B5/wKiom1M_tP7wGPakAAF6_adF_WY121.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/23/B6/wKioL1M_tOOSjKwVAAJEuPc2nCs099.jpg" target="_blank"></a>

測試通路需要驗證;并且可以顯示詳細的httpd伺服器資訊。

15、利用mod_deflate子產品壓縮頁面優化傳輸速度

<code>[Linux85]</code><code>#httpd -M | grep deflate</code>

<code> </code><code>deflate_module (shared)</code>

<code>#主配置檔案内沒有定義;這裡自己建立配置檔案</code>

<code>[Linux85]</code><code>#vim /etc/httpd/conf.d/deflate.conf</code>

<code>SetOutputFilter DEFLATE</code>

<code>                                                                                                                                  </code> 

<code>AddOutputFilterByType DEFLATE text</code><code>/</code><code>plain</code>

<code>AddOutputFilterByType DEFLATE text</code><code>/</code><code>html</code>

<code>AddOutputFilterByType DEFLATE application</code><code>/</code><code>xhtml</code><code>+</code><code>xml</code>

<code>AddOutputFilterByType DEFLATE text</code><code>/</code><code>xml</code>

<code>AddOutputFilterByType DEFLATE application</code><code>/</code><code>xml</code>

<code>AddOutputFilterByType DEFLATE application</code><code>/</code><code>x</code><code>-</code><code>javascript</code>

<code>AddOutputFilterByType DEFLATE text</code><code>/</code><code>javascript</code>

<code>AddOutputFilterByType DEFLATE text</code><code>/</code><code>css</code>

<code># Level of compression (Highest 9 - Lowest 1)</code>

<code>DeflateCompressionLevel </code><code>9</code>

<code>                                                                                                                                                           </code> 

<code># Netscape 4.x has some problems.</code>

<code>BrowserMatch ^Mozilla</code><code>/</code><code>4</code> <code>gzip</code><code>-</code><code>only</code><code>-</code><code>text</code><code>/</code><code>html</code>

<code># Netscape 4.06-4.08 have some more problems</code>

<code>BrowserMatch ^Mozilla</code><code>/</code><code>4</code><code>\.</code><code>0</code><code>[</code><code>678</code><code>] no</code><code>-</code><code>gzip</code>

<code>                                                                                                                                                       </code> 

<code># MSIE masquerades as Netscape, but it is fine</code>

<code>BrowserMatch \bMSI[E] !no</code><code>-</code><code>gzip !gzip</code><code>-</code><code>only</code><code>-</code><code>text</code><code>/</code><code>html</code>

<code>                                                                                                                                </code> 

<code>[Linux85]</code><code>#service httpd restart</code>

<code>Stopping httpd:                                            [  OK  ]</code>

<code>Starting httpd:                                            [  OK  ]</code>

<a href="http://s3.51cto.com/wyfs02/M02/23/B5/wKiom1M_vH6Bk11uAAKye7Vf8UE436.jpg" target="_blank"></a>

測試成功。該功能并不是所有狀态都适合;需要合理的判斷。

二、httpd-2.4的編譯安裝

<b>本文轉自Mr_陳 51CTO部落格,原文連結:http://blog.51cto.com/chenpipi/1390923,如需轉載請自行聯系原作者</b>

繼續閱讀