I am connecting to two tomcat application via the ajp protocol.
both of which are running in separate tomcat virtual host as ROOT.war.
On the server, I have configured the /etc/hosts file
127.0.0.1 localhost tcvh1 tcvh2
apache httpd.conf:
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
#ProxyPreserveHost On
ServerName app1.example.com
ProxyPass / ajp://tcvh1:8082/
ProxyPassReverse / ajp://tcvh1:8082/
</VirtualHost>
<VirtualHost *:80>
#ProxyPreserveHost On
ServerName app2.example.com
ProxyPass / ajp://tcvh2:8082/
ProxyPassReverse / ajp://tcvh2:8082/
</VirtualHost>
Tomcat :
I have the applications deployed as:
app1 -- $CATALINA_HOME/tcvh1/ROOT.war
app2 -- $CATALINA_HOME/tcvh2/ROOT.war
Now,
If I changed the tomcat to run on port 8080, and changed the proxy pass to connect to http://tcvh1:8080, then it works. but if I used the configuration with AJP, it does NOT work.
Why does my host alias not work with AJP? is there a way to make it work?
It doesn't work because the mod_proxy_ajp always passes the host header received by httpd to Tomcat whereas the mod_proxy_http will use the host defined in the ProxyPass unless ProxyPreserveHost is set to On.
Since - as far as httpd is concerned - your virual hosts are app1.example.com and app2.example.com, these are what get passed to your Tomcat instance. Tomcat has no record of these virtual hosts. It has tcvh1 and tcvh2. Therefore all the requests will get routed to the default virtual host (which ever one is defined on your Engine element in server.xml).
There are several ways to fix this:
Rename you Tomcat virtual hosts to match your httpd virtual hosts
Add aliases ( see http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Host_Name_Aliases) to your Tomcat virtual hosts.
Personally, I'd go with option 2. Quicker and simpler.
Related
I had Apache configuration which was using a ProxyPass/ProxyPassReverse with the following example syntax:
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
Then, I moved Apache from port 80, to 8880, and put another web server on port 80. I can access some things correctly now on port 8880 - those files which are hosted directly on Apache. But my proxy pass (to Tomcat) now fails when I try to access it at: http://some.domain:8880/myprog.
How do I correct the ProxyPass/Reseverse to account for the port change? (I assumed, perhaps natively, the port spec was implicit...).
You need to put your configuration on a VirtualHost tag.
<VirtualHost *:8880>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
</VirtualHost>
I have devserver on intranet with ubuntu, apache 2.4. There is some service running on direct ports like yourtrack on port 9000.
When I connecting directly its working properly (http://devserver:9000/).
But I want to make on this format. http://devserver/yourtrack
How could I do this?
You could use apache proxying to your application. So you declare the port 80 virtual host and the use proxy pass to proxy to the other port.
<VirtualHost *:80>
ServerName devserver
ProxyPreserveHost On
ProxyPass /yourtrack http://devserver:9000/
ProxyPassReverse /yourtrack http://devserver:9000/
</VirtualHost>
WARNING: This could have adverse effect on the application you're running depending what it does with http requests.
On my system I have more than one web daemon running, one of them is Apache which is listening on ports 80 and 443. Another only accepts local connections on a different port.
Is it possible for Apache to forward connections to another daemon, wait for the reply before sending it back to the original client?
Possible config file could look like:
<VirtualHost *:80>
ServerName another-hostname.com
ForwardConnectionTo localhost:4949
</VirtualHost>
Use a ProxyPass. Make sure you have mod_proxy and mod_proxy_http enabled:
<VirtualHost *:80>
ServerName another-hostname.com
ProxyPerserveHost On
ProxyPass / http://localhost:4949
</VirtualHost>
I have 3 tomcat instances running on Windows Server 2008 machine. Each one with one app:
http://host:8080/app0
http://host:8081/app1
http://host:8082/app2
How I can configure my server to map an address without the port number?
http://host/app0
http://host/app1
http://host/app2
Is it a tomcat configuration or something with DNS?
Thanks.
Ok, I tried the following:
Set up the Apache 2.2
Configure httpd.conf loading proxy modules
And add a proxy module configuration:
ProxyRequests Off
ProxyPass /app1 http://machine:8081/app
ProxyPassReverse /app1 http://machine:8081/app
<Location "/app">
Order allow,deny
Allow from all
</Location>
Now the redirect works well local in the machine. But it doesn't works when I try access from another machine in the same network. (this another machine can ping 'machine' host. And I tried putting the ip number too).
You can use nginx (http://nginx.org/en/docs/) as proxy for example.
Try simply (no load balancing etc.):
server {
listen here.your.ip:80/YourApp;
location / {
root /path/to/your/webapp;
proxy_pass http://host:8080/YourApp;
}
}
Same way for other ports
It is quite common to use multiple Tomcats behind Apache to do load balancing. While this is not load balancing the principle is the same. Instead of having one application with 3 load-balanced Tomcat workers, you would have 3 applications with 1 tomcat worker each.
You can find the tomcat documentation here: http://tomcat.apache.org/connectors-doc/
Try mod proxy configuration on below code in httpd:
ProxyPass /app0 http://localhost:8080/app0/
ProxyPassReverse /app0 http://localhost:8080/app0/
ProxyPass /app1 http://localhost:8081/app1/
ProxyPassReverse /app1 http://localhost:8081/app1/
ProxyPass /app2 http://localhost:8082/app2/
ProxyPassReverse /app2 http://localhost:8082/app2/
I have a problem configuring apache tomcat ProxyPass directive for two applications that have two different Context Paths in tomcat. The tomcat is running behind an apache and I use the apache to proxy path the requests to tomcat. In apache I want to access both application via a hostname instead of a context path.
Scenario:
tomcat
https://domain:8443/app1
https://domain:8443/app2
in tomcat the applications have the context path app1 and app2
in apache I want to enable both application as follow:
https://app1.host/
https://app2.host/
In apache I have created a configuration for each domain:
ProxyPass / https://localhost:8443/app1
ProxyPassReverse / https://localhost:/8443/app1
The strange thing is app1 is only available through apache using the context path:
https://app1.host/app1
Is it possible to realize such a setup with apache ProxyPass module?
Thx for your help.
You should be able to achieve the result you want by using virtual hosting. Also it's a good idea to pass the requests to tomcat via the AJP protocol instead of HTTPS. Try adding this to the Apache configuration
NameVirtualHost *:443
<VirtualHost *:443>
ServerName app1.host
ProxyPass / ajp://localhost:8009/app1/
</VirtualHost>
<VirtualHost *:443>
ServerName app2.host
ProxyPass / ajp://localhost:8009/app2/
</VirtualHost>
If you haven't changed the default server settings for Tomcat this should work just as it is. Otherwise make sure to specify the AJP port that is configured in Tomcat's conf/server.xml file. There should be a line similar to this:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Make sure that you have the mod_proxy and mod_proxy_ajp modules loaded in Apache configuration, this may vary depending on your Apache installation. Also remove any previously configured 'ProxyPass / ...' lines as they will interfere with the new configuration. Hope this works for you.
you can try
ProxyPass / https://localhost:8443/app1/
ProxyPassReverse / https://localhost:8443/app1/
with the final /