一、运行环境

操作系统 centos7

Apache 版本 2.4.6

网站信息:

  1. 网站目录/var/www/html 网址 blog.web.com
  2. 网站目录/var/www/wxapp 网址 wx.web.com

二、Apache配置

  1. 在 /etc/httpd 目录下新建文件夹 conf.web
  2. 在 conf.web 下新建配置文件 wxapp.conf 并添加以下配置
<VirtualHost *:80>
    DocumentRoot /var/www/wxapp   # 网站目录
    ServerName wx.web.com      #域名
    ServerAliaswx.web.com     #别名
    
# http  重定向到https ,https 证书使用let's ncrypt 具体参考 https://certbot.eff.org/   
RewriteEngine on
RewriteCond %{SERVER_NAME} =wx.hqfa65.top
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<Directory "/var/www/wxapp">
    Options +Includes -Indexes
    AllowOverride All
    Require all granted
</Directory>
  1. 在 conf.web 下新建配置文件 blog.conf 并添加以下配置

    <VirtualHost *:80>
        DocumentRoot /var/www/html   # 网站目录
        ServerName blog.web.com      #域名
        ServerAlias blog.web.com     #别名
        
    # http  重定向到https ,https 证书使用let's ncrypt 具体参考 https://certbot.eff.org/   
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =blog.hqfa65.top
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    
    <Directory "/var/www/html">
        Options +Includes -Indexes
        AllowOverride All
        Require all granted
    </Directory>
  1. 修改 httpd.conf 注释 最外层#DocumentRoot "/var/www/html"
  2. 修改httpd.conf添加一行,内容为IncludeOptional conf.web/*.conf
  3. 重启Apache服务器systemctrl restart httpd

三、Apache服务器使用let’s encrypt配置ssl证书

  1. 安装相关软件

    yum -y install yum-utils
    yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
    
    yum install certbot python2-certbot-apache
  1. 根据提示安装证书

     certbot --apache  #运行此命令后根据提示安装证书即可
文章目录