首先安装SSL,再编译安装APACHE,再配置证书即可 1. 下载安装apache和openssl
网址:http://www.apache.org,http://www.openssl.org
#tar zxvf httpd-2.0.54.tar.gz
#tar zxvf openssl-0.9.7g.tar.gz
编译安装openssl,这个软件主要是用来生成证书:
#cd openssl-0.9.7g
#./config
#make
#make test
#make install
把 openssl放进内核目录下,使其在任何目录下都能运行。
#cd /usr/local/bin
#ln -s /usr/local/ssl/bin/openssl openssl
编译安装apache
#cd /opt/httpd-2.0.54
#./configure --prefix="/opt/apache2" --enable-so --enable-ssl --with-ssl="/usr/local/ssl/bin"
#make
#make install
2. 安装完毕,生成证书:
在/opt/apache2/conf下建立一个ssl.key目录
#cd ../apache2/
#cd conf/
#mkdir ssl.key
然后在该目录下生成证书:
#cd ssl.key/
生成服务器私钥:
#openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.......................++++++
.................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key: //密码
Verifying - Enter pass phrase for server.key: //确认和上面密码相同
生成服务器证书请求,并按要求填些相关证书信息:
#openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: //上面的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:BJ
Locality Name (eg, city) []:BJ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:163
Organizational Unit Name (eg, section) []:TD
Common Name (eg, YOUR name) []:a.test.com//行使 SSL 加密的网站地址。请注意这里并不是单指您的域名,而是直接使用SSL的网站名称 例如:pay.abc.com是一个网站;www.abc.com 是另外一个网站;pay.abc.com 又是另外一个网站。
Email Address []:lala@corp.netease.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:**********
An optional company name []:126
签证:
# openssl x509 -req -days 700 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=AU/ST=Some-State/L=tyl/O=tz/OU=tz/CN=tyl/emailAddress=tangyl@ruyi.com
Getting Private key
Enter pass phrase for server.key: //输入创建key时的密码
3. 修改httpd.conf文件
Apache 一般有2个版本下载,一个是带SSL模块的,一个是不带SSL的,请首先检查自己的SSL是包含了SSL模块的,否则就没法做了。 Apache的参数配置都在httpd.conf文件中,SSL配置也是如此,此外还可以通过include httpd-ssl.conf来包含一个专门配置SSL的配置文件,如果激活了httpd-include ssl.conf,则可以打开httpd-ssl.conf来配置相应参数。
一般,我们直接在httpd.conf文件中直接配置SSL参数:
#加载模块mod_ssl.so,此模块是启用SSL功能必须的。
LoadModule ssl_module modules/mod_ssl.so //静态编进apache内核的则不需要此段
#监听443端口
Listen 443
#建立一个SSL的虚拟站点,避免SSL配置影响原来HTTP的站点配置
NameVirtualHost *:443
NameVirtualHost *:80