简体   繁体   English

文档根目录不适用于Apache的虚拟主机设置

[英]Document Root doesn't work with Virtual Host setting for Apache

I set VirtualHost in httpd.conf like this: 我在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>

And it looks like ok with httpd -S. 使用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

But when I access to http://xxx.255.118.79:8080 , it still access to /var/www/html. 但是当我访问http://xxx.255.118.79:8080时 ,它仍然可以访问/ var / www / html。 Could you kindly tell me how I can make apache2 serve /opt/another_www for port 8080 ? 您能告诉我如何使apache2为/ 8080端口服务/ opt / another_www吗?

Thanks! 谢谢!

I realized that the domain name in has to be discoverable by the local machine that runs Apache. 我意识到,必须由运行Apache的本地计算机才能发现其中的域名。 It means it has to be local IP address or *. 这意味着它必须是本地IP地址或*。

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

After I changed it to *, it started to serve documents under /opt/another/www. 在将其更改为*之后,它开始在/ opt / another / www下提供文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM