Apache and multiple tomcats proxy - apache

I have 1 apache server and two tomcat servers with two different applications. I want to use the apache as a proxy so that the user can access the application from the same url using different paths.
e.g.:
localhost/app1 --> localhost:8080/app1
localhost/app2 --> localhost:8181/app2
I tried all 3 mod proxy of apache (mod_jk, mod_proxy_http and mod_proxy_ajp) but the first application is working, whilst the second is not accessible.
This is the apache configuration I'm using:
ProxyPassMatch ^(/.*\.gif)$ !
ProxyPassMatch ^(/.*\.css)$ !
ProxyPassMatch ^(/.*\.png)$ !
ProxyPassMatch ^(/.*\.js)$ !
ProxyPassMatch ^(/.*\.jpeg)$ !
ProxyPassMatch ^(/.*\.jpg)$ !
ProxyRequests Off
ProxyPass /app1 ajp://localhost:8009/
ProxyPassReverse /app1 ajp://localhost:8009/
ProxyPass /app2 ajp://localhost:8909/
ProxyPassReverse /app2 ajp://localhost:8909/
With the above, I manage to view the tomcat root application using localhost/app1, but I
get "Service Temporarily Unavailable" (apache error) when accessing app2.
I need to keep the tomcat servers separate because I need to restart one of the applications often and it is not an option to save both apps on the same tomcat.
Can someone point me out what I'm doing wrong?
Thank you all.

Related

Apache proxypass configuration for Apache and JBoss application installed on same server node

If I hit - http://10.157.128.170/oneapp application should load index.html from Apache content
And ALL API calls like http://10.157.128.170:25003/oneapp/* (where * could be any API Call) should redirect calls to JBOSS on port :25003/oneapp
What could be the Apache configuration for this requirement ?
My current Configuration is :
ProxyPassMatch ^/oneapp/$ !
ProxyPass /oneapp/index.html !
ProxyPass /oneapp http://10.157.128.170:25003/oneapp
ProxyPassReverse /oneapp http://10.157.128.170:25003/oneapp
where I need to hit : http://10.157.128.170/index.html for going to index.html but I need that to be http://10.157.128.170/oneapp
File I've on Apache Content directory
index.html
app.css
app.js
images
Just add a trailing slash to fix the issue
ProxyPassMatch ^/oneapp/$ !
ProxyPass /oneapp/index.html !
ProxyPass /oneapp/ http://10.157.128.170:25003/oneapp/
ProxyPassReverse /oneapp/ http://10.157.128.170:25003/oneapp/
Also make sure that mod_proxy and mod_proxy_http are enabled.

Apache and Tomcat proxying

Recently, I was in need of using both Apache and Tomcat together in which Apache was to be used as the reverse proxy to forward requests to port 80 to localhost:8080 which I did like this:
<VirtualHost *:*>
ProxyPass / http://localhost:8080/app/
</VirtualHost>
And it works perfectly well.
Now, what I need to do is: I have Tomcat listening and serving on another port 8082. I need to be able to access it using www.mydomain.com:8082. I tried:
<VirtualHost *:8082>
ProxyPass / http://localhost:8082/app/
</VirtualHost>
But no luck. And I can't listen on 8082 because Tomcat is doing that.
What you have above is a (failed) attempt to map the / URL space into two different places. That's never going to work.
When proxying to Tomcat, it's never a good idea to rewrite URL paths (e.g. / -> /app/ because Tomcat is going to get all kinds of confused. It's much better to map individual applications:
<VirtualHost *:*>
ProxyPass /app1/ http://localhost:8080/app1/
ProxyPass /app2/ http://localhost:8080/app2/
ProxyPass /app3/ http://localhost:8082/app3/
ProxyPass /app4/ http://localhost:8082/app4/
# If you need a fall-back application for `/`, just map it last.
ProxyPass / http://localhost:8080/
</VirtualHost>
Note that the last line up there is mapping / to Tomcat's ROOT context (mounted on /'). Don't do this any other way, or you'll spend years trying to make everything work when you could have just done it the recommended way.

How to have Apache server port 8080 display content from localhost:3080

So I have an application the is bound to localhost:3080. When I locally visit "localhost:3080" the application displays in the browser.
I also have an apache server setup listening to the publicIP:8080.
When I visit the publicIP from the outside world, publicIP:8080 loads up.
How can I have it so that when I visit publicIP:8080, the contents of localhost:3080 are displayed onto it?
Is there a way to forward the contents of localhost:3080 to publicIP:8080?
You can create an apache proxy.For example :
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3080/
ProxyPassReverse / http://127.0.0.1:3080/
</VirtualHost>
You will also need to do :
a2enmod proxy
a2enmod proxy_http
service apache2 restart
See more informations there : https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
I assume your application at localhost:3080 acts as a http server.
Then you would simply
ProxyPass "/" "http://localhost:3080/"
Generally its better to use ProxyPass to handle only special locations
<Location "/myCoolApp/">
ProxyPass "http://localhost:3080/"
</Location>
Then if you request http://publicIP:8080/myCoolApp/XYZ your application #3080 will receive the request on URL /XYZ.

What are my options to deploy Go applications alongside PHP applications?

What I'm basically trying to accomplish is having my main website running a CMS written in Go. This will be located at www.example.com.
I also have applications written in PHP located in directories, such as www.example.com/clients/
How can I serve example.com/clients using Apache/PHP while serving example.com using Go built-in web server?
Via mod_proxy in Apache2, you can proxy different paths into different destinations at localhost or anywhere else accessible by your server, including within your local network (if your server can access it).
For this you would use ProxyPass (Apache2 Docs for ProxyPass, which is very useful reading) like the example below:
<VirtualHost *:80>
ServerName some.example.host.xyz
DocumentRoot /var/www/your-document-root
Alias /clients/ /var/www/clients/
ProxyPass /clients/ !
ScriptAlias /something-using-cgi/ /var/www/cgi-stuff/
ProxyPass /something-using-cgi/ !
ProxyPreserveHost On
ProxyPass / http://localhost:9876/
ProxyPassReverse / http://localhost:9876/
ProxyPass /elsewhere/ http://elsewhere.example.host.xyz:1234/
ProxyPassReverse /elsewhere/ http://elsewhere.example.host.xyz:1234/
</VirtualHost>
You'll want to be sure that you set your proxy security such that external users can't use your reverse proxy as a forward proxy, too. You can do that via ProxyRequests as described in the official Apache2 docs. The way I did this on a server is to put this in your server-wide config (you should verify on your own that this is secure enough):
# disables forward proxy
ProxyRequests Off
Andrew Gerrand has a good blog post about this for nginx but the principle is the same for Apache.
You want to set up Apache as a reverse proxy for requests coming in for the Go application.
For Apache you want to look at mod_proxy

Mapping address to multiple tomcat instances

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/