ProxyPass redirect to the same path - apache

I have two management console wildlfy and I want to access to both of them through reverse proxy. For that I did this conf in my httpd reverse proxy:
<VirtualHost X.X.X.X:80>
ServerName reverse.com
ProxyPreserveHost On
RewriteEngine On
<Proxy balancer://wildfly-1>
BalancerMember http://wildfly-1.com route=wildfly-1 disablereuse=On keepalive=On retry=20
ProxySet lbmethod=bybusyness
</Proxy>
RewriteRule ^/wildfly-1-console/?$ / [R]
ProxyPass / balancer://wildfly-1/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / balancer://wildfly-1/
<Proxy balancer://wildfly-2>
BalancerMember http://wildfly-2.com route=wildfly-2 disablereuse=On keepalive=On retry=20
ProxySet lbmethod=bybusyness
</proxy>
RewriteRule ^/wildfly-2-console/?$ / [R]
ProxyPass / balancer://wildfly-2/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / balancer://wildfly-2/
</VirtualHost>
My problem is that when I enter http://X.X.X.X:80/wildlfy1 or 2 it works, the rewriterules works perfectly and redirect to the management console, But only for the first console. I think that the problem is with my rewriterules, it redirect to the same path "/", so my reverse ignore the second redirection. How can I solve that ?
Thanks.

this was to long or a comment. This is what I meant:
<VirtualHost X.X.X.X:80>
ServerName reverse.com
ProxyPreserveHost On
RewriteEngine On
ProxyPass /wildfly-1-console http://wildfly-1.com
ProxyPassReverse /wildfly-1-console http://wildfly-1.com
ProxyPass /wildfly-2-console http://wildfly-2.com
ProxyPassReverse /wildfly-2-console http://wildfly-2.com
</VirtualHost>
This way heach URL is served via a proxy to another site.
Note that this is far from a complete configuration, it is just to show the concept. I was also no able to test it, as I have no access to an Apache right now.
As for the sticky session, you are applying balancer concepts to a single member, so it serves no purpose. The sticky cookie is to ensure you will return to the same instance for every request. Here is you ask for no1, you get no1. If you ask for no2, you get no2. It is not possible for you to ask for /wildfly-1-console and be "proxied" to http://wildfly-2.com.
Now if you want to have a single URL to proxy in front of http://wildfly-1.com AND http://wildfly-2.com, that is a subject for another question (well some research on your part :-)

Related

Redirect subdomain to subdomain+folder

I've linked a subdomain to my Tomcat app, but I don´t want to put the name of the folder to access. I've done this using Apache as a proxy.
<VirtualHost *:80>
ServerName domain.example.com.pe
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /SSHR http://192.168.10.52:8081/SSHR
ProxyPassReverse /SSHR http://192.168.10.52:8081/SSHR
</VirtualHost>
I've tried with this lines:
ProxyPass / http://192.168.10.52:8081/SSHR/
ProxyPassReverse / http://192.168.10.52:8081/SSHR/
It works, but I've some problems with the Tomcat application. So, what I need is something to redirect from example.domain.com.pe to example.domain.com.pe/SSHR.

Apache forward proxy by url parameter

I want redirect any access whose URL parameter is "deep" to local server, and redirect other access to other server.
Forward a request like the following:
① url parameter starting with deep
http*://hostname/bdd?deep=1
→
http*://127.0.0.1:8080/bdd
② other url
→
http*://10.137.213.101:8080/bdd
I am setting my apache conf as the following, but it still does not work.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^deep
RewriteRule "^/bdd(.*)$" /dataviewlinks/ [L]
ProxyPass /dataviewlinks http*://127.0.0.1:8080/bdd
ProxyPassReverse /dataviewlinks http*://127.0.0.1:8080/bdd
ProxyPass /bdd http*://10.137.213.101:8080/bdd
ProxyPassReverse /bdd http*://10.137.213.101:8080/bdd
What could be the solution?
I have done it like this in the past to redirect any network access on port 8080 to another directory.
<VirtualHost *:8080>
ServerName 127.0.0.1
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests On
ProxyPreserveHost On
ProxyPass "/" "http://10.137.213.101:8080/bdd"
ProxyPassReverse "/" "http://10.137.213.101:8080/bdd"
</VirtualHost>
Maybe this would work for you as well.
Also make sure you have enabled proxy mod sudo a2enmod proxy and restart apache

VirtualHost Same ServerName Different Directories

I have a running production website assigned to a host (redmine application). I need to add a new application to the same host as a sub-directory.
This is the current virtualhost configuration for redmine application which runs at base folder of host.
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
RewriteEngine On
RewriteRule ^/(.*)$ balancer://redminecluster%{REQUEST_URI} [P,QSA]
ProxyPass / balancer://redminecluster
ProxyPassReverse / balancer://redminecluster
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
So this application already runs at redmine.hostname.com. I want to add my own application and i want it to run at redmine.hostname.com/myapp/.
Whatever i did, i couldn't achieve this. I must not change the path of redmine, i must add new app to same virtualhost. There are no open ports other than 80, so i must make it run at redmine.hostname.com/myapp/
Basically, the redmine application must reply all requests that do not start with redmine.hostname.com/myapp/. My App should reply all requests that start with redmine.hostname.com/myapp.
What settings should i use?
If your application /myapp is located is c:/myappdir, the easiest way to configure apache to do what you want is to use this configuration:
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
Alias /myapp "c:/myappdir"
ProxyPass /myapp !
ProxyPass / balancer://redminecluster/
ProxyPassReverse / balancer://redminecluster/
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
Using an exclamation point as target for ProxyPass will exclude /myapp from the proxy configuration as documented here. Additionally you don't need a special RewriteRule since you don't modify the requests to redmine, ProxyPass should be enough.
It depends a little on whether your own app is hosted on the apache server itself, or it's proxied to another server/process.
If it's on the apache server itself, then just put 'myapp' into the document root. Then you need to remove your ProxyPass line and replace it with a locationmatch block
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
RewriteEngine On
RewriteRule ^/(.*)$ balancer://redminecluster%{REQUEST_URI} [P,QSA]
<LocationMatch "^(?!/myapp)">
ProxyPassMatch balancer://balancer://redminecluster
</LocationMatch>
ProxyPassReverse / balancer://redminecluster
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
So, the strategy is to forward everything which doesn't match /myapp to your existing redmine application. Everything matching /myapp will go to the document root. If your own app is proxied, then you need another locationmatch block which proxies /myapp to the correct location.

How to forward only *.jsp or *.do requests to Tomcat using mod_proxy?

I am using mod_proxy module to forward all requests for one of my domain to be served by Tomcat. However I want to forward only requests ending *.jsp or *.do or *.something to Tomcat and rest (e.g. *.html, *.php, *.png) to be served by Apache server. How to achieve that using mod_proxy?
Following is sample httpd.conf config that I am using currently:
<VirtualHost *:80>
DocumentRoot /usr/share/tomcat6/webapps/mywebapp
ServerName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
I know that you had found the answer but I write this answer for others that maybe need it:
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
#ProxyPass / ajp://localhost:8009/
ProxyPassMatch ^/(.*\.do)$ ajp://localhost:8009/$1
ProxyPassMatch ^/(.*\.jsp)$ ajp://localhost:8009/$1

Mixing RewriteRule and ProxyPass in Apache

I was working on debugging an issue today related to mixing mod_proxy and mod_rewrite together and I ended up having to use balancer://mycluster in the RewriteRule in order to stop receiving a 404 error from Apache. I have two questions:
1) Is there any other way to get the rewritten URL to go through the balancer without adding balancer://mycluster into the RewriteRule?
2) Is there a way to define all the parameters I defined in ProxyPass (stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off) in either the <Proxy> or RewriteRule? I'm concerned the requests that match the new RewriteRule won't load balance in the same fashion as those that go through ProxyPass (like /app1/something.do)?
Below are the relevant sections of the httpd.conf. I am using Apache 2.2.
<Proxy balancer://mycluster>
Order deny,allow
Allow from all
BalancerMember ajp://my.domain.com:8009 route=node1
BalancerMember ajp://my.domain.com:8009 route=node2
</Proxy>
ProxyPass /app1 balancer://mycluster/app1 stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off
ProxyPassReverse /app1 ajp://my.domain.com:8009/app1
...
RewriteRule ^/static/cms/image/(.*)\.(.*) balancer://mycluster/app1/$1.$2 [P,L]
Looks like I can use the ProxySet directive so the URL's that match the RewriteRule load balance in the same fashion.
<Proxy balancer://mycluster>
Order deny,allow
Allow from all
BalancerMember ajp://my.domain.com:8009 route=node1
BalancerMember ajp://my.domain.com:8009 route=node2
ProxySet stickysession=JSESSIONID|jsessionid scolonpathdelim=On lbmethod=bytraffic nofailover=Off
</Proxy>