apache+mod_ssl

| |
[不指定 2005/08/08 23:03 | by ipaddr ]
参改了一位前人的文章《Apache2 + mod_ssl + php5 完全安装实录》,在此表示感谢

1.安装openssl

一般,RH的系统会自带了RPM包的openssl,可以直接
rpm -ivh openssl*.rpm

另外,需在源代码安装,可参考:
下载最新版本的openssl: http://www.openssl.org/source/
# tar zxvf openssl-0.9.7d.tar.gz
# cd openssl-0.9.7d
# ./config
# make
# make install

2.整合安装mod_ssl

下载apache2: http://httpd.apache.org/download.cgi
我需要mod_ssl的支持,和apache1不同的是,mod_ssl不在是单独的模块,而是放在apache发行包里面了,默认是不启用的,config的时候选择上就可以了。
我使用DSO方式编译安装apache,同时将全部模块都编译好,以方便后来可能的需要。只要编辑httpd.conf,在里面去掉不想要的模块(注释或者删除对应模块的LoadModule行),就可以定制自己的apache咯。
# tar zxvf httpd-2.0.50.tar.gz
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=shared --enable-mods-shared=all --with-ssl=/usr/local/ssl
# make
# make install


Apache有两种使用模块的方法,其一是永久性包含进核心;
如果操作系统支持动态共享对象(DSO),而且能为autoconf所检测,则模块还可以被动态编译。
DSO模块的存储是独立与核心的,可以被核心使用由mod_so模块提供的运行时刻配置指令包含或排除。
如果编译中包含有任何动态模块,则mod_so模块会被自动包含进核心。如果希望核心能够装载DSO,而不实际编译任何动态模块,需要明确指定--enable-so。
(http://kajaa.bbs.us/ApacheManual/install.html)

第一次按照上述方法编译的apache,启动的时候会报错:
# cd /usr/local/apache2
# ./bin/apachectl startssl
Syntax error on line 251 of /usr/local/apache/conf/httpd.conf:
Cannot load /usr/local/apache/modules/mod_ssl.so into server: /usr/local/apache/modules/mod_ssl.so: undefined symbol: X509_free

原因是什么呢?看 http://www.smartframeworks.com/qt-apache-ssl.html
因为按照下面的方法(参看:Apache2 + mod_ssl + php5 完全安装实录(2))安装的openssl默认是没有编译成动态链接库的,因为其文档说openssl的动态链接库还不成熟,可以使用 ./config shared 编译带动态链接库的openssl,但是还处于试验阶段。
解决这个问题的办法是:将mod_ssl静态的编译到apache里面。
请使用下面的方法重新来过:)
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl --enable-mods-shared=all
# make
# make install
(ipaddr注:好象要先mkdir /usr/local/ssl,另外,--enable-mods-shared=all可以不要)

这次启动apache的时候又发现一个错误:
# cd /usr/local/apache2
# ./bin/apachectl startssl
Syntax error on line 108 of /usr/local/apache2/conf/ssl.conf:
SSLCertificateFile: file '/usr/local/apache2/conf/ssl.crt/server.crt' does not exist or is empty

这又是什么原因呢?因为我们没有配置ssl,需要生成ssl需要的证书。
以前使用apache1+mod_ssl的时候,make之后有一个这样的步骤
$ make certificate
可以用来生成ssl所用到的证书。
现在没有这个工具了,只能自己动手生成了,对证书不熟悉的人,有一个工具可以使用:http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
# cd /usr/local/apache2/conf
# tar zxvf ssl.ca-0.1.tar.gz
# cd ssl.ca-0.1
# ./new-root-ca.sh                         (生成根证书)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
...........................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key:              (输入一个密码)
Verifying - Enter pass phrase for ca.key:  (再输入一次密码)
......
Self-sign the root CA...                   (签署根证书)
Enter pass phrase for ca.key:              (输入刚刚设置的密码)
........
........                                   (下面开始签署)
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Certification Services Division]:ACSTAR
Common Name (eg, MD Root CA) []:WISCOM CA
Email Address []:acmail@wiscom.com.cn

这样就生成了ca.key和ca.crt两个文件,下面还要为我们的服务器生成一个证书:
# ./new-server-cert.sh server              (这个证书的名字是server)
......
......
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Secure Web Server]:ACSTAR
Common Name (eg, www.domain.com) []:acmail.wiscom.com.cn
Email Address []:acmail@wiscom.com.cn

这样就生成了server.csr和server.key这两个文件。
还需要签署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key:             (输入上面设置的根证书密码)
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'CN'
stateOrProvinceName   :PRINTABLE:'JiangSu'
localityName          :PRINTABLE:'NanJing'
organizationName      :PRINTABLE:'Wiscom System Co.,Ltd'
organizationalUnitName:PRINTABLE:'ACSTAR'
commonName            :PRINTABLE:'acmail.wiscom.com.cn'
emailAddress          :IA5STRING:'acmail@wiscom.com.cn'
Certificate is to be certified until Jul 16 12:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
(如果这里出现错误,最好重新来过,删除ssl.ca-0.1这个目录,从解压缩处重新开始。)

下面要按照ssl.conf里面的设置,将证书放在适当的位置。
# chmod 400 server.key
# cd ..
# mkdir ssl.key
# mv ssl.ca-0.1/server.key ssl.key
# mkdir ssl.crt
# mv ssl.ca-0.1/server.crt ssl.crt

然后就可以启动啦!
# cd /usr/local/apache2
# ./bin/apachectl startssl

对于这个提示:
httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
只需要编辑httpd.conf,找到ServerName xxxx这一行,去掉前面的注释即可。

//很大部分参考《Apache2 + mod_ssl + php5 完全安装实录》,只做了一些小说明,原文作者写得太详细了。

在此基础上可直接安装PHP,不再重复PHP的安装了。

Net | 评论(0) | 引用(0) | 阅读(7791)