0

I am using the following VirtualHost and mod_proxy to proxy all requests for my 'api' subdomain to my Java webservice which is located at webapps/webservice on my Tomcat.

<VirtualHost *:80>
    ServerName api.mydoamin.com
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass /webservice http://localhost:8080
    ProxPassReverse / http://localhost:8080
</VirtualHost>

My problem is if I type 'api.mydomain.com' I get redirected to 'api.mydomain.com/webservice' and I get a 404 error because "webservicewebservice" is not available.

Does anybody know what to do?

Solution: Even though I've tried this solution before, Stony was right! The problem in my case was that, even if I hadn't changed anything there, I had to restart Tomcat to make it working. I restarted Apache multiple times but that didn't change anything.

2 Answers 2

0

I don't know if i understand your problem correctly but if you don't want the webservice in your URL. Then set your Proxy Pass to /.

<VirtualHost *::80>
    ServerName api.mydoamin.com
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://localhost:8080/webservice/
    ProxPassReverse / http://localhost:8080/webservice/
</VirtualHost>

Or do you want to run your webservice under that domain? And you don't want the redirect?

3
  • I want to run my webservices under the address 'api.mydomain.com' but when I enter this address in my browser it "redirects" me to 'api.mydomain.com/webservices' and I don't want this "redirect".. Sep 26, 2015 at 17:37
  • Just that you get me correctly my webservice project is not located at the root path of my Tomcat it's in a subdirectory called 'webservice' Sep 26, 2015 at 17:38
  • Then proxy your traffic directly to the correct url http://localhost:8080/webservice. Then you should Proxy all from / to /webservice of your Tomcat. Sep 26, 2015 at 17:40
0

After some testing and many many errors, I finally came up with the following solution.

I set up my apache virtual host like this:

<VirtualHost *:80>
    ProxyRequests Off
    ProxyPreserveHost On
    <Proxy *>
        Order deny, allow
        Allow from all
    </Proxy>                                                                        
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    ServerName api.mydomain.com
</VirtualHost>

Now it just proxies all requests for api.mydomain.com to my Tomcat on port 8080 without pointing to a specific directory.

Then I added this to /etc/tomcat7/server.xml:

<Host name="api.mydomain.com" appBase="webapps">
    <Context path="" docBase="webservice" />
</Host>

As ProxyPreserveHost is activated in my Apache virtual host Tomcat gets the host name of the original request and is able to decide itself which content to deliver.

With appBase="webapps" the content seems to be delivered from the root directory, even if its located somewhere else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .