CentOS 7.2 Apache 配置https

步骤一:安装ssl扩展模块

yum install mod_ssl

步骤二:从阿里云下载https证书,并上传到自定义文件夹。例如,我放置在/etc/httpd中certs文件夹中(文件夹名称自定义)

CentOS 7.2 Apache 配置https_第1张图片

 

步骤三 : 为方便以后多域名,在/etc/httpd/conf.d目录下创建https域名配置文件

   
DocumentRoot "/home/store/webroot"
Servername domain
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn
SSLEngine on

SSLCertificateFile /etc/httpd/certs/domian_public.crt
SSLCertificateChainFile /etc/httpd/certs/domian_chain.crt
SSLCertificateKeyFile /etc/httpd/certs/domian.key

步骤四:重启apache服务,访问域名

systemctl restart httpd

步骤五:若想要从http自动跳转至https,可在.htaccess加上以下代码(注:该http那边需要配置当前域名,若服务器只有一项目可在http.conf结尾加上以下代码即可)

    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]

 

 

你可能感兴趣的:(CentOS 7.2 Apache 配置https)