- 论坛徽章:
- 0
|
一,安装环境:AS4(update5)+httpd-2.2.4.tar.gz
二,安装步骤:
1,依次安装apr和apr-util
# tar zxvf httpd-2.2.4.tar.gz
# cd httpd-2.2.4
# cd srclib/apr
# ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child USE=ipv6
# make && make install
#cd ../apr-util
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
# make && make install
2,安装httpd
# cd httpd-2.2.4
#./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --with-mpm=worker --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-ssl --with-ssl=/usr/include/openssl
# make
# make install
注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-mods-shared=all //编译全部的模板,对于不需要我们可以在httpd.conf去掉。
--enable-cache //支持缓存
--enable-file-cache //支持文件缓存
--enable-mem-cache //支持记忆缓存
--enable-disk-cache //支持磁盘缓存
--enable-static-support //支持静态连接(默认为动态连接)
--enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
--enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
--enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
--enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
--enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
--enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
--enable-static-checkgid //使用静态连接编译 checkgid
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP
--with-mpm=worker // 让apache以worker方式运行
--enable-ssl // 编译 ssl模块。
三,配置
1,vi /usr/local/apache2/conf/httpd.conf
# 监听443端口,支持https连接
取消注释 httpd.conf 中的 Include conf/extra/httpd-ssl.conf
保存httpd.conf,退出。
2,设置SSL并创建自己的CA
# cd /usr/share/ssl/misc
# ./CA -newca
屏幕上出现如下的提示:CA certificate filename (or enter to create)
这是要求输入要创建的CA的证书文件名, 可以直接回车或输入证书文件名。
Making CA certificate ...
Generating a 1024 bit RSA private key
.........++++++
................................++++++
writing new private key to './demoCA/private/./cakey.pem'
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:-
此时要求输入和验证CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
至此,在当前目录下生成了demoCA的目录,CA的证书就在该目录下,文件名为cacert.pem
生成服务器的证书请求
# ./CA -newreq
屏幕上出现如下的提示:
Generating a 1024 bit RSA private key
.....................................................++++++
.....++++++
writing new private key to 'newreq.pem'
Enter PEM pass phrase:
Verifying password - Enter PEM pass phrase:
此时要求输入和验证服务器的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
Please enter the following 'extra' attributes
to be sent with your certificaterequest
A challenge password []:
An optional company name []:
.Request (and private key) is in newreq.pem
这是要求输入服务器的相关信息。
此时,在当前目录下生成了一个名为newreq.pem的文件,包含了要生成服务器数字证书的请求。
签署证书
# ./CA -sign
屏幕上出现如下的提示:
Using configuration from /usr/share/ssl/openssl.cnf
Enter PEM pass phrase:
此时一样需要输入CA的私钥口令、国家代码(中国是CN)、省份、城市或地区、组织或企业名称、部门名称、CA的名称或服务器的主机名称、管理员电子邮件地址。
Certificate is to be certified until Nov 19 13:46:19 2002 GMT (365 days)
Sign the certificate? [y/n]:y
这时显示证书请求文件中的各项信息,并询问是否要签署证书,回答y,进行签署。
1 out of 1 certificate requests certified, commit? [y/n]y
回答y,会显示已经签署的证书的信息,并在当前目录下生成服务器的证书文件newcert.pem。
此时,需要做如下操作:
# mkdir /usr/local/apache2/conf/ssl.crt/
# mkdir /usr/local/apache2/conf/ssl.key/
# cp /usr/share/ssl/misc/newcert.pem /usr/local/apache2/conf/ssl.crt/server.pem
# cp /usr/share/ssl/misc/newreq.pem /usr/local/apache2/conf/ssl.key/server.pem
3, 更改服务器的证书文件的相关配置
# vi /usr/local/apache2/conf/extra/httpd-ssl.conf
查找并修改
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. Keep
# in mind that if you have both an RSA and a DSA certificate you
# can configure both in parallel (to also allow the use of DSA
# ciphers, etc.)
SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.pem
#SSLCertificateFile /usr/local/apache2/conf/server-dsa.crt
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server.pem
#SSLCertificateKeyFile /usr/local/apache2/conf/server-dsa.key
四,测试和说明
假如Web服务器的IP是192.168.71.110
在浏览器的URL地址栏里输入 http://192.168.71.110/,浏览器便会显示APACHE安装时确省的Test Page.
在浏览器的URL地址栏里输入 https://192.168.71.110/,注意:是 https 而不是http !
浏览器会提示站点已经采用了SSL进行数据的加密传输.由于我们的CA证书不是浏览器缺省的信任的根证书,所以,浏览器会说无法确认服务器的证书可信。暂时不管,一直NEXT,最后,浏览器会显示:It works!
可以把CA的证书放在非SSL的站点上,让浏览器下载并安装CA证书,并将其设置成可信任的根证书,便可解决上面的问题.
解除HTTPD起动时的口令输入:
由于安全的原因,Web服务器的私钥是口令加密了的,每次重新起动HTTPD或Linux时,都会要求输入Web服务器的私钥的口令。
如果要解除HTTPD起动时的口令输入,可以这样:
# cd /usr/local/apache2/conf/ssl.key/
# cp server.pem server.pem.org
# openssl rsa -in server.pem.org -out server.pem
# chmod 400 server.pem
另外在网上看到一个方法,我没有试。有兴趣的可以试下。
创建SSL密码自动应答文件,否则每次Apache启动的时候,都会要求你输入SSL的密码.
创建 /usr/local/apache2/conf/ssl.key/sendsslpwd ,内容如下.
#!/bin/bash
SSLpasswd="YOUR PASSPHRASE"
echo $SSLpasswd
chmod 755 /usr/local/apache2/conf/ssl.key/sendsslpwd
此时,Web服务器的私钥已经没有口令加密,一定要确保server.pem文件除root外,任何用户均无权读取它。 |
|