Ubuntu feisty中的apache2安装包有BUG,安装后缺少apache2-ssl-certificate命令,这样如果我们要启用apache的ssl服务,就生成不了站点证书,这个BUG可能在后续的升级中会修复,但是目前官方还未有明确修复该BUG的决定。
不过,现在已经有人做了这个工作了,我们可以通过自己编译apache2源码来安装,安装方法如下:
首先下载并解压这个修复包:
wget http://librarian.launchpad.net/6917265/files.tar
tar xvf files.tar然后安装Apache2 deb源代码及相关编译依赖包,然后编译安装apache2:
sudo apt-get build-dep apache2
sudo apt-get source -d apache2
dpkg-source -x apache2_2.2.3-3.2build1.dsc
cd apache2-2.2.3
fakeroot debian/rules binary(如果没有安装fakeroot,请先安装)
sudo dpkg -i ../*.deb(您也可以选择性的安装您需要的Apache2 deb包)如果您不愿自己编译,可以到这里下载编译好的Apache2 Deb包。
这样安装的apache2包含完整的工具,下面我们来配置Apache2 ssl支持:
先生成站点证书:
sudo apache2-ssl-certificate -days 365接着启用Apache2 的ssl模块:
sudo a2enmod ssl增加ssl端口443监听:
echo “Listen 443” | sudo tee -a /etc/apache2/ports.conf
创建并启用ssl站点:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
sudo gedit /etc/apache2/sites-available/ssl
修改其内容,设定对应端口,启用ssl,指定站点证书文件位置等,修改后类似如下:
NameVirtualHost *:443
<virtualhost *:443>
ServerAdmin webmaster@localhost
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
DocumentRoot /var/www/
<directory />
Options FollowSymLinks
AllowOverride None
</directory>
<directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<directory “/usr/lib/cgi-bin”>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ “/usr/share/doc/”
<directory “/usr/share/doc/”>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</directory>
</virtualhost>
修改default站点配置,指定其端口为80:
sudo gedit /etc/apache2/sites-available/default将其内容前面两行修改为:
NameVirtualHost *:80
<virtualhost *:80>然后启用上面配置的ssl站点:
sudo a2ensite ssl启动Apache2:
sudo /etc/init.d/apache2 start大功告成,现在您可以使用https://127.0.0.1测试服务是否正常启动,也可以使用以下命令查看apache ssl服务是否启动:
netstat -na|grep :443正常的话您应该可以看到如下的输入:
tcp6 0 0 :::443 :::* LISTEN