天天看点

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>

继续阅读