Apache配置SSL证书以及HTTP重定向HTTPS

如果一开始只安装了httpd,还要安装mod_ssl才能开启SSL

所以记得yum install mod_ssl

配置HTTPS

  • 前4行按照腾讯云去配置证书文件和秘钥文件
  • ServerName是在DNS解析里配置的A记录
  • ProxyPassProxyPassReverse是我用来代理到8081端口的配置,如果是静态目录应该配置DocumentRoot
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/httpd/cert/jenkins/2_jenkins.bnuztuhms.cn.crt
    SSLCertificateKeyFile /etc/httpd/cert/jenkins/3_jenkins.bnuztuhms.cn.key
    SSLCertificateChainFile /etc/httpd/cert/jenkins/1_root_bundle.crt

    ServerName jenkins.bnuztuhms.cn
    ProxyPass / http://www.bnuztuhms.cn:8081/
    ProxyPassReverse / http://www.bnuztuhms.cn:8081/
VirtualHost>

HTTP重定向HTTPS

将所有到80端口(HTTP)的请求重写/重定向到443端口(HTTPS)即可,不要忘记ServerName应与443端口的配置一致

<VirtualHost *:80>
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https://%{SERVER_NAME}$1 [L,R]
    ServerName jenkins.zhuyst.cc
VirtualHost>

你可能感兴趣的:(Apache配置SSL证书以及HTTP重定向HTTPS)