user3236816
user3236816

Reputation: 41

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 [email protected]
    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 [email protected]
    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!

Upvotes: 1

Views: 3909

Answers (1)

user3236816
user3236816

Reputation: 41

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 [email protected]
  DocumentRoot /opt/another_www/

After I changed it to *, it started to serve documents under /opt/another/www.

Upvotes: 2

Related Questions