简体   繁体   中英

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

I set VirtualHost in httpd.conf like this:

<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.

[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. Could you kindly tell me how I can make apache2 serve /opt/another_www for port 8080 ?

Thanks!

I realized that the domain name in has to be discoverable by the local machine that runs Apache. It means it has to be local IP address or *.

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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