相信很多同学都见到过https的链接,大部分使用在安全支付或者安全级别很高的页面,主要是为了信息安全,当然对于访问速度上较http会慢一些,这里我们主要讲解一下apache的服务器下安装配置ssl证书的一些步骤。
首先你需要安装ssl模块和openssl,这里呢,如果你是源代码编译安装你需要开启这个模块:[shell]
./configure --prefix=/usr/local/apache --enable-ssl=static --enable-rewrite --enable-so --with-ssl=/usr/local/openssl[/shell]
如果你是编译安装在httpd.conf文件下可能有如下配置指令:[shell]
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf[/shell]
这样是网路上流传最广的版本,但是大部分情况下配置方式都不是这样子,ssl有单独的配置文件/etc/httpd/conf.d/ssl.conf,包括modules的加载和vhost的配置等。
其中static表示静态编译,如果是shared就是动态编译,动态编译启动都会加载一次模块,其中我们目前的php一般都是以动态模块方式加载进apache,作为apache的一个模块在运行的。
如果你是yum的rpm安装可以这样来安装ssl模块[shell]
yum install mod_ssl openssl[/shell]
你可以这样查看你的ssl模块是不是安装了[shell]
httpd -M[/shell]
然后我们使用openssl来生成相关文件[shell]
# Generate private key
openssl genrsa -out ca.key 1024
# Generate CSR
openssl req -new -key ca.key -out ca.csr
# Generate Self Signed Key
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
# Copy the files to the correct locations
cp ca.crt /etc/pki/tls/certs
cp ca.key /etc/pki/tls/private/ca.key
cp ca.csr /etc/pki/tls/private/ca.csr[/shell]
以上是从cenos的wiki上截取的,其实上面的步骤还需要补充一下,就是还需要一张中级证书(因证书类型而已,我的是这样),而且csr可以不导入。休要增加以下一句
SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
这样你的一张服务器证书,中级证书,密钥文件都导入了。接下来需要配置一个vhost来运行https,端口为443,vhost配置如同apache的80端口的vhost,不过这个vhost是建立在[shell]/etc/httpd/conf.d/ssl.conf[/shell]
其中这个文件只能配置一个VirtualHost,因此你可以将文件中默认的VirtualHost去掉,加入自己的:[shell]
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
<Directory /var/www/html/8seasons>
AllowOverride All
</Directory>
DocumentRoot /var/www/html/8seasons
ServerName www.8seasons.com
</VirtualHost>[/shell]
然后重启apache,即可。
这里给出一个证书查看工具,是一个java小工具:
点击下载