【问题标题】:Document Root doesn't work with Virtual Host setting for Apache文档根目录不适用于 Apache 的虚拟主机设置
【发布时间】:2014-02-17 01:19:29
【问题描述】:

我在 httpd.conf 中这样设置 VirtualHost:

<VirtualHost xxx.255.118.79:80>
    ServerAdmin hoge@hoge.foo.com
    DocumentRoot /var/www/html
    ServerName main.foo.com
    ErrorLog logs/main.foo.com-error_log
    TransferLog logs/main.foo.com-access_log
</VirtualHost>

<VirtualHost xxx.255.118.79:8080>
    ServerAdmin hoge@hoge.foo.com
    DocumentRoot /opt/another_www/
    ServerName anotherhost.foo.com
    ErrorLog logs/host.foo.com-error_log
    TransferLog logs/host.foo.com-access_log
</VirtualHost>

使用 httpd -S 看起来没问题。

[iron@birdwatch html]$ sudo httpd -S
VirtualHost configuration:
xxx.255.118.79:80      main.foo.com (/etc/httpd/conf/httpd.conf:1012)
xxx.255.118.79:8080    anotherhost.foo.com (/etc/httpd/conf/httpd.conf:1020)
Syntax OK

但是当我访问http://xxx.255.118.79:8080 时,它仍然访问/var/www/html。 你能告诉我如何让 apache2 为端口 8080 服务 /opt/another_www 吗?

谢谢!

【问题讨论】:

    标签: apache


    【解决方案1】:

    我意识到,运行 Apache 的本地机器必须能够发现 in 中的域名。 这意味着它必须是本地 IP 地址或 *.

    <VirtualHost *:8080>
      ServerAdmin hoge@hoge.foo.com
      DocumentRoot /opt/another_www/
    

    我把它改成*后,它开始提供/opt/another/www下的文件。

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 2018-08-14
      • 2019-06-29
      • 2015-09-05
      • 2014-12-04
      • 2021-02-08
      • 2015-05-27
      • 2015-02-04
      相关资源
      最近更新 更多