apache - 来自不同子域的 Apache VirtualHost 重定向
问题描述
我有一个 DO droplet (Ubuntu 18.04),我想在其上托管两个站点。假设液滴的 IP 为 101.1.1.1。现在我希望从另一台服务器(具有不同的 IP,比如说 104.1.1.1.)子域指向站点。假设 siteone.example.org 和 sitetwo.example.org。所以我按照指南设置我的 Apache VirtualHost,如下所示:
<VirtualHost *:80>
ServerAdmin webmaster@example.org
ServerName siteone.example.org
ServerAlias www.siteone.example.org
DocumentRoot /var/www/siteone/public_html
<Directory /var/www/siteone/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
但是,当我在浏览器中按 siteone.example.org 时,我没有得到任何响应。我在两端都设置了 A 名称以指向 101.1.1.1。有什么我做错了吗?
解决方案
您想在同一台机器上拥有 2 个网站,每个网站都有一个 IP 地址?所以:
- 在系统上配置两个 IP
- 在 Listen 中设置两个 IP:80
- 每个 IP / 域配置一个 VirtualHost
像这样:
Listen *.80
<VirtualHost 101.1.1.1:80>
ServerName siteone.example.org
ServerAlias www.siteone.example.org
ServerAdmin webmaster.example.org
DocumentRoot "/var/www/siteone/public/html"
<Directory /var/www/siteone/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/siteone_error.log
CustomLog ${APACHE_LOG_DIR}/siteone_access.log combined
</VirtualHost>
<VirtualHost 104.1.1.1:80>
ServerName sitetwo.example.org
ServerAlias www.sitetwo.example.org
ServerAdmin webmaster.example.org
DocumentRoot "/var/www/sitetwo/public/html"
<Directory /var/www/sitetwo/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/siteotwo_error.log
CustomLog ${APACHE_LOG_DIR}/sitetwo_access.log combined
</VirtualHost>
在您的 DNS 中,配置:
- 101.1.1.1 siteone.example.org www.siteone.example.org
- 104.1.1.1 sitetwo.example.org www.sitetwo.example.org
推荐阅读
- html - 使第二行文本在第一行文本下对齐
- django - Django - 我正在尝试将用户对象添加到 ManyToManyField,但它不断添加所有用户对象
- amazon-web-services - Kinesis 视频流 - 多个生产者
- swift - Swift - AES base64 + md5 解密
- codenameone - 如何将多个容器绑定在一起?
- javascript - 如何克隆网页及其 css 元素和脚本?
- node.js - 如何通过不同的api使用socket io连接服务器和客户端?
- javascript - Discord.js Avatar 命令无法提及用户
- apache-spark - 使用聚合函数时出现火花数据框错误
- javascript - 如何使用 Python 从 javascript 网页中抓取 HTML