centOS7 apache ssl证书安装配置

背景说明:服务器是centOS7.4 七牛申请的免费ssl证书
默认apache是没有安装SSL模块的,所以需要安装,接着使用命令:
yum install -y mod_ssl

apache目录 /usr/local/apache/
vim conf/httpd.conf
再 Listen 80下面添加一行
Listen 443
找到 #LoadModule ssl_module modules/mod_ssl.so 和 #Include conf/extra/httpd-ssl.conf,去掉前面的#号注释;

先将要修改的文件备份是个好习惯。
编辑Apache根目录下 conf/extra/httpd-ssl.conf 文件,修改如下内容:
<VirtualHost 0.0.0.0:443>
DocumentRoot "/data/www/default"
ServerName ding.com
ServerAlias www.ding.com
<Directory /data/www/default>
#AllowOverride伪静态
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl/www.ding.com.cer
SSLCertificateKeyFile /usr/local/apache/conf/ssl/www.ding.com.key
SSLCertificateChainFile /usr/local/apache/conf/ssl/www.ding.com_ca.crt
</VirtualHost>
配置完成后,重新启动 Apache 就可以使用https://www.domain.com来访问了。

若是腾讯云的免费ssl证书是,对应修改如下内容:
SSLCertificateFile /usr/local/apache/conf/2_www.domain.com_cert.crt
SSLCertificateKeyFile /usr/local/apache/conf/3_www.domain.com.key
SSLCertificateChainFile /usr/local/apache/conf/1_root_bundle.crt

如果要强制网站使用HTTPS,httpd-vhost.conf文件配置如下:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /data/www/default
<Directory /data/www/default>
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order Deny,Allow
Require all granted
DirectoryIndex index.php index.html index.htm
</Directory>
#强制http转向为https
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
</VirtualHost>

上一篇:CCF——相邻数对201409-1


下一篇:wamp配置apache虚拟主机支持多域名访问localhost