Ubuntu下Apache SSL的配置方法

基于的Ubuntu版本Edgy,在Ubuntu下面安装配置Apache都比较简单。相应的配置文件位置如下:

默认站点在 /var/www/
配置文件在 /etc/apache2/
日志在 /var/log/apache/
启动脚本是 /usr/sin/apache2ctl 或者 /etc/init.d/apache2

1,安装Apache
$sudo apt-get install apache2

2,开启SSL模块
$sudo a2enmod ssl

3,创建证书
可以使用apache内置的工具创建默认的证书,通过-days指定有效期。
$sudo apache2-ssl-certificate

另外我们可以使用openssl来创建
$sudo openssl req -x509 -newkey rsa:1024 -keyout apache.pem -out apache.pem -nodes -days 999
注:在要求输入Common Name (eg, YOUR name) 时,输入你的主机名。

4,编辑SSL的配置
我们可以将当前的默认站点配置文件拷贝一份,然后进行修改
#vi /etc/apache2/sites-enabled/001-ssl
把端口改为443
加入SSL认证配置
其它的根据需要自己定制 与普通配置无异
NameVirtualHost *:443
<virtualhost *:443>
ServerSignature On
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem

ServerAdmin webmaster@localhost
#[......]

修改普通http方式的配置
#vi /etc/apache2/sites-enabled/000-default
把端口改为80
NameVirtualHost *:80
<virtualhost *:80>
ServerAdmin webmaster@localhost
#[......]

编辑Apache端口配置,加入443端口(SSL的)
#vi /etc/apache2/ports.conf:
Listen 80
Listen 443

重新载入Apache的配置
#/etc/init.d/apache2 force-reload
或者重新启动Apache2
#/etc/init.d/apache2 restart

0 Responses to "Ubuntu下Apache SSL的配置方法"