[问题]设置apache的ssl出错了

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
znonline
帖子: 35
注册时间: 2008-08-22 9:52

[问题]设置apache的ssl出错了

#1

帖子 znonline » 2008-09-05 9:44

设置完apache+ssl,重启apache.就报错了:

代码: 全选

 httpd(no pid file) not running
然后我去查看apache的log文件。发现原来是访问证书时的出错了。

代码: 全选

[Thu Sep 04 16:17:30 2008] [error] Init: Unable to read server certificate from file /etc/apache2/ssl/apache.pem
[Thu Sep 04 16:17:30 2008] [error] SSL Library Error: 218529960 error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
[Thu Sep 04 16:17:30 2008] [error] SSL Library Error: 218595386 error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error
apache.pem是我生成的证书文件,但是我又把证书删了,从新建立还是报错,我上网上也搜索不到相关的文章,有人配置过ssl 和建立过证书吗,你们建立的时间出错了吗?

我配置ssl是参照这篇文档:

代码: 全选

http://forum.ubuntu.org.cn/viewtopic.php?t=139570
头像
str263
帖子: 56
注册时间: 2006-09-13 23:59

#2

帖子 str263 » 2008-09-05 13:43

启用ssl

(1)下载ssl.ca-0.1.tar.gz(适合新手使用)到/etc/httpd(Apache2.2.4安装时指定的配置文件目录)
#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: (刚刚输过的密码)
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) [MY]:CN
State or Province Name (full name) [Perak]:HeNan
Locality Name (eg, city) [Sitiawan]:Zhengzhou
Organization Name (eg, company) [My Directory Sdn Bhd]:Benet Ltd
Organizational Unit Name (eg, section) [Certification Services Division]:Marion
Common Name (eg, MD Root CA) []:Benet CA
Email Address []:knightma@yeah.net
如此可以生成ca.key和ca.crt两个文件;其中的省份、公司等内容可以按照你自己的相法来设定。

接下来要为服务器生成一个证书:
# ./new-server-cert.sh server (这个证书的名字是server)
No server.key round. Generating one
Generating RSA private key, 1024 bit long modulus
....++++++
.............++++++
e is 65537 (0x10001)
Fill in certificate data
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) [MY]:CN
State or Province Name (full name) [Perak]:HeNan
Locality Name (eg, city) [Sitiawan]:Zhengzhou
Organization Name (eg, company) [My Directory Sdn Bhd]:Benet Ltd
Organizational Unit Name (eg, section) [Secure Web Server]:Marion
Common Name (eg, www.domain.com) []:localhost
Email Address []:knightma@yeah.net
You may now run ./sign-server-cert.sh to get it signed
执行结束后生成了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:'HeNan'
localityName :PRINTABLE:'Zhengzhou'
organizationName :PRINTABLE:'Benet Ltd'
organizationalUnitName:PRINTABLE:'Marion'
commonName :PRINTABLE:'localhost'
emailAddress :IA5STRING:'knightma@yeah.net'
Certificate is to be certified until Nov 21 11:58:38 2007 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

(2)接下来要按照/etc/httpd/extra/httpd-ssl.conf里面的设置,将证书放在适当的位置。
#cp ./server.key /etc/httpd
#cp ./server.crt /etc/httpd
#cd ..
#chmod 400 server.key

(3)编辑/etc/httpd/httpd.conf
找到如下一句,将前面的注释#去掉
#Include /etc/httpd/extra/httpd-ssl.conf
而后重启apache即可
#killall -9 httpd
#/usr/local/apache/bin/apachectl start

(4)查看监听端口,确认里面有:443端口
#netstat -tnl

(5)https://localhost
znonline
帖子: 35
注册时间: 2008-08-22 9:52

#3

帖子 znonline » 2008-09-05 16:02

我是按照这篇配置的, 怎么跟楼上的又如此之大的区别啊,到底那种合适?
配置Subversion
代码:

代码: 全选

sudo apt-get install subversion
为了从apache通过web dav访问subversion
代码:

代码: 全选

sudo apt-get install libapache2-svn
然后对subversion作配置,具体的可参考subversion wiki,更详细的请参考subversion官方向导

都完成之后,从http://localhost/svn/project可以看到subversion的内容了,用户鉴权视具体配置而定,如果采用了basic password验证的方式,由于http是明文传送,甚不安全。那就再配上SSL吧。

步骤其实也很简单:
apt-get自动安装的apache2里其实已经包含了mod_ssl,但没有激活,所以我们先激活它
代码:

代码: 全选

a2enmod ssl
然后确认一下/etc/apache2/ports.conf里包含有"Listen 443"之类的字段
接下来就是配置证书,比较推荐使用apache2-ssl-certificate脚本命令,在Ubuntu 7.04以后至今似乎该命令消失了,不要紧,我们自己动手写:
编辑当前用户的.bashrc
代码:

代码: 全选

gedit ~/.bashrc
新增一条
代码:

代码: 全选

alias apache2-ssl-certificate='sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem'
重新开个命令窗口,新增的apache2-ssl-certificate就可以使用了,但是且慢,还要改一个地方
代码:

代码: 全选

gedit /usr/sbin/make-ssl-cert
把第118行的
代码:

代码: 全选

openssl req -config $TMPFILE -new -x509 -nodes -out $output -keyout $output > /dev/null 2>&1
改为
代码:

代码: 全选

openssl req -config $TMPFILE -new -x509 -nodes -out $output -keyout $output -days 3650 > /dev/null 2>&1
这样一来将来生成的证书有效期从默认仅仅1个月延长到了10年,:)
另外上面我们自己写的alias命令中,证书将被放在/etc/apache2/ssl目录中,如果该目录不存在,新建一个
代码:

代码: 全选

sudo mkdir /etc/apache2/ssl
现在可以生成证书了
代码:

代码: 全选

apache2-ssl-certificate
按提示填写相应内容至完成
剩下的工作就是配置站点了
代码:

代码: 全选

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
编辑一下
代码:

代码: 全选

sudo gedit /etc/apache2/sites-available/ssl
其中的
代码:

代码: 全选

NameVirtualHost *
换为
代码:

代码: 全选

NameVirtualHost *:443
其中的
代码:

代码: 全选

<VirtualHost *>
换为
代码:

代码: 全选

<VirtualHost *:443>
在</VirtualHost>之前加上(之所以仅仅加上这两行是因为在/etc/apache2/mods-available/ssl.conf里已经有很多关于ssl的global配置了,当然用户也可以酌情修改)
代码:

代码: 全选

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
把站点跑起来
代码:

代码: 全选

a2ensite ssl
大功告成,重新启动apache2
代码:

代码: 全选

sudo /etc/init.d/apache2 restart
试一试https://localhost/svn/project,ie会弹出security alert的窗口,ff会显示是否添加exception的信息,一切正常,因为我们用的是自认证的方式,浏览器不认识CA,呵呵。但SSL已经起作用了!
回复