0

On my self-hosted server, I've got an Apache serving several websites. On the same machine, I've also got other services that don't run on Apache. I bought a domain name. Here is what I'm trying to do:

  • domain.tld redirects to /var/www/site1
  • sub1.domain.tld redirects to localhost:8080
  • sub2.domain.tld redirects to localhost:8081

Here is what I've tried:

<VirtualHost domain.tld:80>
    ServerName domain.tld
    DocumentRoot /var/www/site1
</VirtualHost>

<VirtualHost sub1.domain.tld:80>
    ServerName sub1.domain.tld
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

<VirtualHost sub2.domain.tld:80>
    ServerName sub2.domain.tld
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
</VirtualHost>

Now, if I enable only one virtual host at the time, it works. But when multiple virtual hosts using proxy directive are enabled at the same time, they always redirect to the same proxy.

What can I do to make this work ? Any suggestions ?

Thanks in advance ! :)

Draxx
  • 11
  • 3
  • I'm assuming you have DNS (or hostfile, for debugging) entries for all three domains, and they all point to the same IP? Also, do you have a [NameVirtualHost](http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost) directive? – Ulrich Schwarz Oct 05 '15 at 15:51
  • Hello ! Yes, I have a type A DNS entry for domain.tld, and CNAME type entries for sub1.domain.tld and sub2.domain.tld, which all point to the same IP. I didn't have a NameVirtualHost directive, but I've added it. My VirtualHost now look like this : NameVirtualHost *:80 ... Unfortunately, the result is still the same :/ – Draxx Oct 06 '15 at 09:11
  • domain.tld and sub1.domain.tld work, but sub2.domain.tld points to sub1.domain.tld. – Draxx Oct 06 '15 at 09:38

0 Answers0