how to config apache point to another index in different server? - apache

I am configuring 3 tiers setup(webserver, database server, and application server). I want to separate everything into 3 three servers. I have already separated between the application server and the database server. Regarding to webserver and application server, I don't know how to config apache to point to my application server. I tried to share file and folder from application server to webserver already with samba share, but it still did not work. The problem is apache server can access the resource in the other server(application server).
If you everyone used to solved or faced this problem. Could you please help me?
Thank in advance.

As a part of an old assignment I had achieved something similar using below config.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
<Proxy "balancer://mycluster">
BalancerMember "http://10.0.0.1:8001"
BalancerMember "http://10.0.0.1:8002"
BalancerMember "http://10.0.0.1:8003"
BalancerMember "http://10.0.0.1:8004"
BalancerMember "http://10.0.0.1:8005"
BalancerMember "http://10.0.0.1:8006"
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / "balancer://mycluster/" stickysession=BALANCEID
ProxyPassReverse / "balancer://mycluster/"
</VirtualHost>
For your case, I feel changing your Virtual Host as below must do the magic.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
<Proxy "balancer://mycluster">
BalancerMember "http://192.168.2.35:8000"
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / "balancer://mycluster/" stickysession=BALANCEID
ProxyPassReverse / "balancer://mycluster/"
</VirtualHost>
Also ensure that you enable the lbmethod_byrequests_module in your apache.

You just need a basic reverse proxy configuration. The absolute basics are loading mod_proxy, mod_proxy_http, and using ProxyPass to match the URL's you want to pass to the backend system.

Related

Apache load-balancer: direct to specific application based on URL

I have multiple applications deployed in Tomcat's webapps folder (app1.0, app1.1, app1.2 etc.). When I hit www.example.com:8080/app1.0, the corresponding application appears.
But how to do it on the load-balancing server? For instance, I have a website on which I can click a button (app1.0, app1.1, app1.2 etc.) and an URL pops up like: www.lb.com/app1.0/.../... How to direct to the app based on application version in URL? Use RewriteCond and regex and pass it to ProxyPass? I don't really how to script it, anyone could help? :)
Edit: This is what I done for the 2 apps for 1 Tomcat and 2 apps for 2 Tomcat, but I got 404 sometimes because the Tomcat that has another version has been chosen by the load-balancer.
<VirtualHost *:80>
#Add a http header to explicitly identify the node and be sticky
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
#Declare the http server pool
<Proxy "balancer://plf">
BalancerMember "http://worker1.com:8080" route=worker1
BalancerMember "http://worker2.com:8080" route=worker2
ProxySet stickysession=ROUTEID
ProxySet lbmethod=bybusyness
</Proxy>
#Common options
ProxyRequests Off
ProxyPreserveHost On
#Declare the redirection for the http requests
ProxyPassMatch "/app(.*)" "balancer://plf/app$1"
ProxyPassReverse "/app(.*)" "balancer://plf/app$1"
This is how I did it:
1) define a balancer proxy:
<Proxy balancer://portalcluster stickysession=JSESSIONID>
BalancerMember ajp://TOMCATSERVER1:8009 route=TOMCARSERVER1-0
BalancerMember ajp://TOMCATSERVER2:8009 route=TOMCATSERVER2-100
</Proxy>
2) proxy to it in your VirtualHost:
Listen 443
<Virtualhost *:443>
ServerName example.com
Alias /static /var/www/portalstatic
ProxyPass /static !
ProxyPass / balancer://portalcluster/
ProxyPassReverse / balancer://portalcluster/
</Virtualhost>
NB I removed a lot of configuration from these, that are not related to the question (logs, deny clauses, certificate directives, ...). This is just to illustrate the way I did the proxy.
NB2 I did leave the /static trick since this is usually something you will want to do. Static files must stay on the HTTP, and not send them from Tomcat all the time.

apache2 proxy redirect configuration

This has been asked a bunch of time I realize but I still can't seem to get it working. Here is my situation. I have 2 servers on my network. Server A is public facing which hosts my website. My second server also has apache running with a web application which I would like to access externally. I am not exactly sure how to configure this. My current config looks like this
NameVirtualHost *:2323
<VirtualHost *:2323>
ProxyPass / http://192.168.1.7/ampache
ProxyPassReverse / http://192.168.1.7/ampache
servername slave-1
ProxyPreserveHost On
ProxyRequests Off
</VirtualHost>
So I would like all traffic on https://my_domain.xx:2323 to redirect to 192.168.1.7/ampache
Thank you
I fixed it by doing the following
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass /airsonic http://192.168.1.7:8088/airsonic
ProxyPassReverse /airsonic http://192.168.1.7:8088/airsonic

Load balancer with apache httpd and wildfly for rest web services with mod_proxy

I have an apache load balancer with mod_proxy and wildfly (apache 224 and wildfly 9).
I have 4 servers in domain in wildfly and the load balancer works fine with a "hello world" app, and in the balancer manager i can see how the requests are sent to each server.
The thing is, When I use the app that has some REST web services, i am sending the request with a GET method and some headers for authentication, and somehow, the application is responding with error when i access it through the load balancer, but if I send it directly to the server, it works correctly.
my cofiguration goes as follows
<VirtualHost *:80>
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080/ loadfactor=25
BalancerMember http://localhost:8230/ loadfactor=25
BalancerMember http://localhost:8330/ loadfactor=25
BalancerMember http://localhost:8430/ loadfactor=25
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
<Location /test>
Order allow,deny
Allow from all
</Location>
ProxyPass /test balancer://mycluster stickysession=JSESSIONID
I am testing using postman and sending the requests with a get method and a header for authentication: basic {base64 code} as follows:
http://127.0.0.1/test/myproject.ws/myproject/get_list?key=T11108101191&page=1
and this results in error.
when i try this:
http://127.0.0.1:8080/myproject.ws/myproject/get_list?key=T11108101191&page=1
This goes ok
and when i try the above, but with a post method, it gets the same error as in the load balancer.
Any idea of what am i doing wrong?
PS: I've tried putting in the WEB-INF/web.xml of the project, but i still get the same error.
Thanks to Dusan Bajic, he saw the problem I had. In the balancer member i was finishing the route with "/" and when I used the ProxyPass, i was starting with "/", duplicating that character. Somehow, with the helloworld app it worked correctly, but when i pass parameters, it failed.
The new configuration goes as follows:
<VirtualHost *:80>
ProxyRequests Off
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080 loadfactor=25
BalancerMember http://localhost:8230 loadfactor=25
BalancerMember http://localhost:8330 loadfactor=25
BalancerMember http://localhost:8430 loadfactor=25
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
<Location /test>
Order allow,deny
Allow from all
</Location>
ProxyPass /test balancer://mycluster stickysession=JSESSIONID
</VirtualHost>

mod_proxy: sticky session does not work

I have two JBoss AS 7 servers and I'm doing load balancing using mod_proxy. Almost everything works fine besides sticky sessions. I have session id in a cookie not in the URL as JSESSIONID.
Here is my apache configuration:
NameVirtualHost *:80
<VirtualHost *:80>
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=Off
ProxyPassReverse / balancer://tutcluster/
ProxyPassReverse / http://server1:8080/
ProxyPassReverse / http://server2:8080/
ProxyPreserveHost On
ProxyRequests Off
<Location / >
Order deny,allow
Allow from All
</Location>
<Proxy balancer://mycluster/>
BalancerMember http://server1:8080 route=jbossWeb1 retry=60
BalancerMember http://server2:8080 route=jbossWeb2 retry=60
</Proxy>
</VirtualHost>
OK, I've found it. There were two problems Firstly I forgot to set jvmRoute property in the JBoss configuration. So I set:
<system-properties>
<property name="jvmRoute" value="nodeX"/>
</system-properties>
and changed workers configuration to:
BalancerMember http://server1:8080 route=nodeX retry=60
The second problem was nofailover=Off. It probably caused that some parts of the static content was loaded from one server and some parts of it -- from another one.

mod_proxy isn't using the port defined in my balancermembers

I'm trying to set up my apache load balancer to proxy to the same backend clusters to apps running on different ports. The cluster definitions are like this:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
BalancerMember http://192.168.2.11:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://192.168.2.10:81
BalancerMember http://192.168.2.11:81
</Proxy>
In the load balancer, one of the vhost needs to talk to both, so in the vhost definition I have:
ProxyRequests Off
ProxyPreserveHost Off
SSLProxyEngine On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /feed balancer://wordpress-cluster/feed lbmethod=byrequests
ProxyPassReverse /feed balancer://wordpress-cluster/feed
ProxyPass / balancer://corporate-cluster/ lbmethod=byrequests
ProxyPassReverse / balancer://corporate-cluster/
when requesting for '/' , I get the content served from the port 80 app, not the port 81 app.
Would anyone know on what is happening? it looks like this might be a case of overzealous worker sharing, but shouldn't specifying the different ports prevent that?
Is there something else I should do?
Forgot to mention: this is using apache 2.2.4-1 on a centos box.
Thanks in advance!
Tim
OK, so I still don't know what happened. Did 2 steps to fix my problem:
1) split the cluster into 2 1-machine clusters and things worked:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://192.168.2.11:81
</Proxy>
But of course that killed balancing and failover support... not good
Second option, create dns aliases to ensure that the balancermembers looked different (even though they point to the same boxes:
<Proxy balancer://wordpress-cluster>
BalancerMember http://192.168.2.10:80
BalancerMember http://192.168.2.11:80
</Proxy>
<Proxy balancer://corporate-cluster>
BalancerMember http://corp01:81
BalancerMember http://corp02:81
</Proxy>
And voila! The setup is now working for me :)