Apache配置多域名
一、运行环境
操作系统 centos7
Apache 版本 2.4.6
网站信息:
- 网站目录
/var/www/html
网址blog.web.com
- 网站目录
/var/www/wxapp
网址wx.web.com
二、Apache配置
- 在 /etc/httpd 目录下新建文件夹 conf.web
- 在 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>
在 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>
- 修改 httpd.conf 注释 最外层
#DocumentRoot "/var/www/html"
- 修改httpd.conf添加一行,内容为
IncludeOptional conf.web/*.conf
- 重启Apache服务器
systemctrl restart httpd
三、Apache服务器使用let’s encrypt配置ssl证书
安装相关软件
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
根据提示安装证书
certbot --apache #运行此命令后根据提示安装证书即可
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭