简体   繁体   中英

Host Tomcat7 WebApp on domain behind Apache2 with mod_proxy

I have installed an application with context /sampleApp on Tomcat7 running Linode. I also have an Apache server installed.

I have done some configuration as below, through which I am able to redirect the requests from www.example.com to the root of tomcat. But I want to be able to serve /sampleApp whenever somebody requests the domain name like www.example.com .

Here is the configuration I have done so far:

Included and enabled a virtual host www.example.com in Apache2

<VirtualHost *:80>

  ServerName www.example.com
  ServerAlias example.com

  ProxyRequests Off
  ProxyPreserveHost On

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

  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://www.example.com/
</VirtualHost>

And added proxy support in Tomcat7 server.xml

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" proxyName="www.example.com" 
                proxyPort="80"/>

I have search SO and ServerFault and Google too but cant find something that works for me.

Did you add this entry in /etc/hosts?

127.0.0.1 www.example.com

If you did try this:

ProxyPass / http://www.example.com:8080/sampleApp
ProxyPassReverse / http://www.example.com:8080/sampleApp

Otherwise:

ProxyPass / http://localhost:8080/sampleApp
ProxyPassReverse / http://localhost:8080/sampleApp

and remove the proxyPort from your server.xml

ps: remember to restart both tomcat and apache2

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