【问题标题】:apache2 VirtualHost subdomain configuration not workingapache2 VirtualHost子域配置不起作用
【发布时间】:2016-11-19 12:07:49
【问题描述】:

我想要的是,www.example.com 重定向到 example.com,这是可行的,但我无法添加另一个 VirtualHost,它允许管理员使用 admin.example.com。

这是我的 .conf 文件:

<VirtualHost *:80>
ServerName www.example.com
ServerAlias old.website.com
DocumentRoot /var/www/redirect

<VirtualHost *:80>
ServerName admin.example.com
DocumentRoot /var/www/admin

<VirtualHost *:80>
ServerName example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

但是,如果我输入 admin.example.com,我会被重定向到 example.com,并且如果我使用其他任何内容作为子域,例如 test.example.com 或 any.example.com,则会显示正常的 example.com 站点但是在 URL 字段中,您仍然可以看到原始 URL(anything.example.com,...),而使用 admin.example.com 时却不是这样。我在 /var/www/redirect 目录中的 .htaccess 文件如下所示:

RewriteEngine on
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
ErrorDocument 404 /index.html

【问题讨论】:

  • 确保在更改服务器配置后重新启动 apache。还要调试更多在您的第二个虚拟主机中放置一些错误。然后尝试,如果达到,如果可以,以后可以调试。
  • /var/www/admin中有.htaccess吗?
  • @Chand Pakash 如果我在重新加载 apache 时添加了一个错误:“apache2.service 的作业失败。有关详细信息,请参阅 'systemctl status apache2.service' 和 'journalctl -xn'。”
  • @Dusan Bajic 不,/var/ww/admin 中没有 .htaccess
  • @ZockerAxel 你把东西绑定到 80 端口了吗?

标签: apache subdomain


【解决方案1】:

好的,这似乎是由我的浏览器数据引起的仅限 google-chrome 的错误,如果其他人遇到问题,请尝试在 Chrome 中使用 Icognito 模式,它应该可以在那里工作。

感谢 Chand Prakash 帮助我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-24
    • 2021-05-06
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 2011-11-02
    相关资源
    最近更新 更多