Using Apache as proxy server + Tomcat - apache

I am trying to show custom page when tomcat is down, in order to do that i am usign apache server. I am trying to redirect all request to tomcat (localhost:8080), except request which start with '/error', how can I do that? I have tried something like this in httpd.conf file:
ErrorDocument 503 /error/503.html
<IfModule proxy_http_module>
ProxyPass /error http://localhost/ retry=0
ProxyPassReverse /error http://localhost/
ProxyPass / http://localhost:8080/ retry=0
ProxyPassReverse / http://localhost:8080/
</IfModule>
But didn't success.

Did you even look at the httpd documentation for ProxyPass before asking your question?
You want
ProxyPass /error !
to exclude paths starting with /error

Related

Apache configuration proxy pass

I want to configure a server to listen to localhost adress with proxy pass.
Fist, I added a proxy pass configuration like that:
ProxyPass /test http://localhost:5959/ nocanon
ProxyPassReverse /test http://localhost:5959/
ProxyPassReverse /test http://domain_name.net/
The index is working fine, but the problem is when i click on some button to be redirected to another page. I expected the redirection would be like : http://domaine_name.net/test/anotherpage.php but it didn't work.
I tried another configuration but it didn't work
ProxyPass /test/ http://localhost:5959/test/
ProxyPassReverse /test/ http://localhost:5959/test/
ProxyPassReverse /test/ http://domain_name.net/test/
How can I resolve this issue ?
Do not put 2 ProxyPassReverse directives. Only one. And it should match the ProxyPass destination. So your first ProxyPassReverse only is required.
ProxyPass /test http://localhost:5959/ nocanon
ProxyPassReverse /test http://localhost:5959/
From the documentation for ProxyPassReverse, (https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassreverse):
This directive lets Apache httpd adjust the URL in the Location,
Content-Location and URI headers on HTTP redirect responses. [...]
You said in your question:
I expected the redirection would be like :
http://domaine_name.net/test/anotherpage.php but it didn't work.
this is normal. A proxy hides the final destination server to the client. If you want to redirect the client, do not use a proxy. Use mod_rewrite (RewriteRule and others).

Configure Apache with multiple ProxyPass

i am trying to configure my apache server as proxy to serve two internal services , one listening on 8080 and should receive traffic on specific URL and the other listening on 8077 and should receive all other http traffic
I deployed and configured apache on the same server where these two services running and it is listening to 443 along with all SSL configuration and it is working fine
also I enabled the proxy_module, proxy_http_module and proxy_http2_module
What I want to achieve
if the requested URL is /webhook1 --> pass it to EP1 http://localhost:8080 and
any other requested URL should be passed to EP2 http://localhost:8077
My Current Configuration towards the first service
ProxyPass /webhook1 http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080
Now I want to define another proxy pass to be something like
ProxyPass / http://localhost:8077
ProxyPassReverse / http://localhost:8077
putting both configuration together is not working , appreciate your help in how to configure apache to achieve my requirement
Thank you in advance
Put the ProxyPass rules in the correct order as required
if you want to evaluate /webhook1 rule and send it to 8080, else send the traffic to 8077 the rules should be on the following order
ProxyPass /webhook1 http://localhost:8080
ProxyPassReverse /webhook1 http://localhost:8080
ProxyPass / http://localhost:8077
ProxyPassReverse / http://localhost:8077
You may write ssl.conf file under /etc/apache2/sites-enabled/ as follows:-
RewriteEngine on
ProxyPass /webhook1 http://127.0.0.1:8080/
ProxyPassReverse /webhook1 http://127.0.0.1:8080/
RewriteRule ^/$ /webhook1/ [R,L]
RewriteEngine on
ProxyPass / http://127.0.0.1:8087/
ProxyPassReverse / http://127.0.0.1:8087/
RewriteRule ^/$ /EP2/ [R,L]
It will automatically redirects to HTTPS if ssl certificate is configured in apache2.

apache ignore htaccess and reach tomcat

I've have a java application running on tomcat and i'm using the apache mod_proxy module to pass the files to tomcat, however tomcat seems to be ignore the .htaccess files, here my vhost.conf. How can I instruct apache to read the .htaccess
< Proxy *>
Order deny,allow
Allow from all
< /Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
my htaccess got one rule as
RewriteRule ^/login(.*)$ /system/customer/portal/1$1 [R]
my apache ignore it and reach tomcat right away ..
i was trying to use
ProxyPass /login !
but no success , any tips ?
You can use ProxyPassMatch for this with regex for excluding these locations:
ProxyPassMatch ^/(login|system/customer/portal/) !

configure tomcat7 and apache2

So I have tried several tutorials, however I am missing something and I hope someone could help me.
I have an ubuntu 12.04 server running with tomcat7 and apache2 and I am trying to reach an application (JSF 2.2) running on tomcat via apache2.
The application running on tomcat is working perfectly fine if I am accessing it like this: example.com:8080/demo.
I am trying to access it via apache2 on the following URL: demo.example.com
So far the main page is loading, but the navigation within the application is not.
If the application is sending me to example.com:8080/demo/page2.xhtml instead of demo.example.com/page2.xhtml I am somehow redirected to
demo.example.com/demo/page2.xhtml and get a HTTP Status 404.
And now the million dollar question: what am I doing wrong?
Here is my httpd.conf file:
<VirtualHost demo.mydomain.com:80>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://localhost:8009/demo/
ProxyPassReverse / ajp://localhost:8009/demo/
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
In the server.xml from tomcat7 I added the following entry:
<Connector port="8009" URIEncoding="UTF-8" protocol="AJP/1.3" redirectPort="8080"/>
In the libapache2-mod-jk "workers.properties" I have the following entries:
workers.tomcat_home=/var/lib/tomcat7
workers.java_home=/usr/lib/jvm/java-8-oracle
ps=/
worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker
Please update ProxyPass setttings as below.
ProxyPass /demo/ ajp://localhost:8009/demo/
ProxyPassReverse /demo/ ajp://localhost:8009/demo/
Or
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
alternative you can use the http connector (default 8080). these must be activated in server.xml.
ProxyPass /demo/ http://localhost:8080/demo/
ProxyPassReverse /demo/ http://localhost:8080/demo/
if the URI /demo under / to deliver, than follow configuration. For this, however, the links must be relative to demo, otherwise there will be problems
ProxyPass / http://localhost:8080/demo/
ProxyPassReverse / http://localhost:8080/demo/

How to exclude UserDir paths from ProxyPass

I want to configure apache UserDir cooperating with ProxyPass, that is, want all requests but starting with /~ passed to proxy.
Firstly I have ProxyPass settings for a Rails application as bellow:
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
and, now I want to add public_html UserDir setting to this.
In other words, I want the requests to http://example.com/hoge/fuga goes to rails app, but those to http://example.com/~userrefer to refer to /home/user1/public_html directory.
How can I do this?
I've solved the problem by adding the line bellow to the apache config;
ProxyPassMatch ^/~ !
Does the below work?
ProxyPass /~ !
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
! will tell mod_proxy not to forward requests beginning /~