Pablo
Pablo

Reputation: 3467

Configuring Virtual Hosts Apache

I have been trying to configure my apache server to support virtual hosts, these hosts, would then redirect any request made at port 80 to different applications hosted in a Jboss AS, so for example my configuration would be like this:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass / http://localhost:8080/contextPath
ProxyPassReverse / http://localhost:8080/contextPath
ProxyPreserveHost On 
ProxyPassReverseCookiePath / / 

</VirtualHost>

However the problem is that when I'm trying to access http://www.testdomain.com, the url gets redirected effectively to localhost:8080, however, I got a duplicated context path. I.E: http://www.testdomain.com/contextPath/contextPath.

Any ideas why is this happening. Thanks a lot.

Upvotes: 1

Views: 6244

Answers (2)

Dennis Lomans
Dennis Lomans

Reputation: 21

I had the same issue and this was solved by adding forwardslashes to the urls.

ProxyPass / http://localhost:8080/contextPath/
ProxyPassReverse / http://localhost:8080/contextPath/

That solved it for me !

Full example for a single virtual host file. I have several, one for each domain and subdomain.

ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName        enter.name.here
        ProxyPass         / http://127.0.0.1:8080/<contextPath>/
        ProxyPassReverse  / http://127.0.0.1:8080/<contextPath>/
        ErrorLog /var/log/apache2/somelog.log
        CustomLog /var/log/apache2/somecustom.log common
</VirtualHost>

Upvotes: 2

sanimalp
sanimalp

Reputation: 819

You need to remove the "ProxyPass" and "ProxyPassReverse" entries, unless you really are trying to proxy something. If the jboss AS is on another server, then you need to retain the proxy entries, but it looks to me like you might be making it too difficult if the content is on one machine and not multiples.

If you want one server to use different base folders as the root for 2 different domains, then you would need to configure the 2 domains by specifying the DocumentRoot parameter.

for example, if I wanted to host google.com and yahoo.com on one computer, my virtualhost entries would contain:

<VirtualHost *:80>
ServerName www.google.com
DocumentRoot /var/www/Google
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
DocumentRoot /var/www/Yahoo
</VirtualHost>

Then, your root directories for each server will go in the google folder and the yahoo folder, respectively.

If you are trying to proxy a completely different machine, then the following should work:

<VirtualHost *:80>
ServerName www.google.com
ProxyPass / www.google.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
ProxyPass / www.yahoo.com
</VirtualHost>

Your entry specifically doesn't make much sense. I think it should look like:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass /contextPath http://localhost:8080
ProxyPassReverse /contextPath http://localhost:8080
</VirtualHost>

Upvotes: 1

Related Questions