Apache reverse proxy for Kibana - apache

I'm currently trying to set up an Apache server to redirect e.g localhost/kibana to Kibana at localhost:5601.
I've tried adding this to apache2.conf:
ProxyPass /kibana http://localhost:5601
ProxyPassReverse /kibana http://localhost:5601
However it gets stuck on the Kibana "loading components" page and never actually loads fully. It works when changed to this:
ProxyPass /kibana/ http://localhost:5601/
ProxyPassReverse /kibana/ http://localhost:5601/
Obviously it's not ideal to force the user to enter the extra / at the end though, so I've tried rewriting the URL in .htaccess:
RewriteEngine On
RewriteRule http://localhost/kibana$ http://localhost/kibana/
But the rewrite doesn't seem to work. I've set AllowOverride to all and enabled the rewrite module, as well as played around with various different rewrite/proxy rules but haven't had any luck so far.

I have finished my apache configuration file for kibana with elasticsearch. It may be useful for you:
/etc/httpd/conf.d/kibana.conf:
ProxyRequests On
ProxyPass /app/kibana http://127.0.0.1:5601/app/kibana
ProxyPassReverse /app/kibana http://127.0.0.1:5601/app/kibana
ProxyPass /elasticsearch http://127.0.0.1:9200/
ProxyPassReverse /elasticsearch http://127.0.0.1:9200/
Alias /bundles/ /opt/kibana/optimize/bundles/
<Directory /opt/kibana>
Require all granted
</Directory>
This way it does not require any additional "/" and it works with default kibana configuration file.

Related

Apache Reverse Proxy configuration - Subdomains

I am trying to configure an Apache server to have 2 subdomains making use of a reverse proxy. I am able to redirect traffic to the first subdomain (first.example.com) and retrieve content from the https site successfully. However, whenever I try to access the second subdomain I end up getting content from the first, and since routes don't match my local website, I get a not found page.
I would like to know what can I adjust from my current configuration so I can get content from my localhost site to.
Here is my current configuration:
<Proxy *>
Require all granted
</Proxy>
SSLProxyEngine On
ProxyRequests Off
SSLProxyCheckPeerCN off
SSLProxyCheckPeerExpire off
SSLInsecureRenegotiation on
SSLProxyVerify none
SSLVerifyClient none
SSLProxyCheckPeerName off
<VirtualHost first.example.com:80>
ServerName first.example.com
ProxyPass /first https://stackoverflow.com
ProxyPassReverse /first https://stackoverflow.com
ProxyPassMatch ^/(.*)$ https://stackoverflow.com/$1
</VirtualHost>
<VirtualHost second.example.com:80>
ServerName second.example.com
ProxyPass /site http://localhost/site
ProxyPassReverse /site http://localhost/site
ProxyPassMatch ^/(.*)$ http://localhost/site/$1
</VirtualHost>
Thank you very much in advance!
Best Regards!
Edgar Martínez.
Your current configuration is conflicting with itself. ProxyPass and ProxyPassMatch does the same thing (in regex) but you declared it both with different rules.
ProxyPass /site http://localhost/site
Rule says: anyone that visits http://second.example.com/site will be fed content from http://localhost/site. If you visit http://second.example.com/foo, you get nothing.
The match line
ProxyPassMatch ^/(.*)$ http://localhost/site/$1
Rule says: Anyone that visits http://second.example.com/site will be fed content from http://localhost/site/site. If you visit http://second.example.com/foo, you get http://localhost/site/foo.
If you use the Match version (regex), you're also out of luck for the reverse rule which doesn't have a regex version. Though, I'm not certain you actually need the reverse rule.
As to why your second request got result from the first... I have no idea.

Apache Reverse Proxy not redirecting URL with special charcaters

I have set up a reverse proxy using apache mod_proxy, and it is working fine for all the URLs I set up, except some URLs which contain special characters (specifically *)
I tried encoding the special characters, as well as using the nocanon flag. But none seems to work. I'm basically trying to run kibana behind a RP, and need to eliminate/replace the special character (use , instead of *) used by Kibana to query elasticsearch. Below is my reverse proxy configuration -
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
# works fine
ProxyPass /kibana http://10.19.225.20:5601/app/kibana
ProxyPassReverse /kibana http://10.19.225.20:5601/app/kibana
# works fine
ProxyPass /elasticsearch http://10.19.225.20:5601/elasticsearch
ProxyPassReverse /elasticsearch http://10.19.225.20:5601/elasticsearch
# Doesn't work
#ProxyPass /elasticsearch/.kibana/_mapping/*/field/_source http://10.19.225.20:5601/elasticsearch/%2Ekibana/%5Fmapping/%2A/
#ProxyPassReverse /elasticsearch/.kibana/_mapping/*/field/_source http://10.19.225.20:5601/elasticsearch/%2Ekibana/%5Fmapping/%2A/
# Doesn't work
#ProxyPass /elasticsearch/%2Ekibana/%5Fmapping/%2A/ http://10.19.225.20:5601/elasticsearch/%2Ekibana/%5Fmapping/index-pattern%2Csearch%2Cconfig/ nocanon
#ProxyPassReverse /elasticsearch/%2Ekibana/%5Fmapping/%2A/ http://10.19.225.20:5601/elasticsearch/%2Ekibana/%5Fmapping/index-pattern%2Csearch%2Cconfig/
# Doesn't work, just a test to use , char in target
#ProxyPass /elasticsearch/.kibana/index-pattern http://10.19.225.20:5601/elasticsearch/.kibana,kib2/index-pattern nocanon
#ProxyPassReverse /elasticsearch/.kibana/index-pattern http://10.19.225.20:5601/elasticsearch/.kibana,kib2/index-pattern
#RewriteEngine on
#RewriteRule ^/index-pattern /_search?fields=
# Doesn't work
ProxyPass /elasticsearch/kibana/%5Fmapping/%2A http://10.19.225.20:5601/elasticsearch/kibana/%5Fmapping/index%2Dpattern%2Csearch%2Cconfig nocanon
ProxyPassReverse /elasticsearch/kibana/%5Fmapping/%2A http://10.19.225.20:5601/elasticsearch/kibana/%5Fmapping/index%2Dpattern%2Csearch%2Cconfig
# Doesn't work
#ProxyPass /elasticsearch/.kibana/_mapping/* http://10.19.225.20:5601/elasticsearch/.kibana/_mapping/index-pattern,search,config
#ProxyPassReverse /elasticsearch/.kibana/_mapping/* http://10.19.225.20:5601/elasticsearch/.kibana/_mapping/index-pattern,search,config
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
In the commented lines, are the various things I tried but none seems to be working. Specifically I'm trying to replace the URL 'http://10.19.225.20/elasticsearch/kibana/_mapping/*/field/source?=some_number' generated by Kibana with http://10.19.225.20/elasticsearch/.kibana/_mapping/index-pattern,search,config/field/source?=some_number I think I need some URL Rewrite Rule, in addition with RP configuration, but not sure how to do it as I haven't used Rewrite Rules before.
Any help/suggestions would be appreciated.

double proxy statements for apache

As you can see I am trying to get both / and /BowlingFacelets/faces/ to point to the same place.
The problem is that the JSF pages will add /BowlingFacelets/faces/ when I sumbit the forms. I however don't want the end user to have to type such a long statement to start the app. Is there a way to do this?
Note that this will work if I manually add
score.megahooked.com/BowlingFacelets/faces to the URL
ProxyPass / http://megahooked.com:8080/
ProxyPassReverse / http://megahooked.com:8080/
This will not work correctly
score.megahooked.com/createEvent.xhtml
since when submitting the new URL will be
score.megahooked.com/BowlingFacelets/faces/updateEvent.xhtml which is not found.
<VirtualHost *:80>
ServerName score.megahooked.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://megahooked.com:8080/BowlingFacelets/faces/
ProxyPassReverse / http://megahooked.com:8080/BowlingFacelets/faces/
ProxyPass /BowlingFacelets/faces/ http://megahooked.com:8080/BowlingFacelets/faces/
ProxyPassReverse /BowlingFacelets/faces/ http://megahooked.com:8080/BowlingFacelets/faces/
</VirtualHost>
The solution could be the using of mod_proxy_html. It can parse HTML documents and rewrite URLs inside. Here for example I make the application "restfrontend" (mapped to "/restfrontend") accessible as root application (mapped to "/")
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLMeta On
ProxyHTMLLogVerbose On
ProxyHTMLURLMap ^/restfrontend()$ $1 [LR]
ProxyHTMLURLMap /restfrontend/ /
ProxyPassReverseCookiePath /restfrontend /
ProxyHTMLDoctype HTML
I would strongly dis-advice to do it. This module is very hard to configure. Configuration of two possible paths in the same time will be a nightmare.
Much better solution is to deploy the application as ROOT directly in the Tomcat and add some redirects for additional URLs shortcuts (RewriteRule with [R=301] option).

Apache reverse proxy: how to redirect relative URLs in external site back to itself?

I need to bypass cross-site scripting restrictions in order to show users a map when they click a link from an external site which I have loaded inside an iframe (external.com/onlyforme). I learned that the easiest way to do this is to set up a reverse proxy so that Apache would retrieve external.com/onlyforme when I access local.com/external, and make it so that it appears to be coming from my domain.
This mostly works, but when external.com/onlyforme/index.html tries to access external.com/onlyforme/site_media/script.js, this gets redirected to local.com/site_media/script.js, which is not what I want. Instead, I would like this to be redirected to the correct URL inside external.com/onlyforme, so that the external site works as expected.
How can I do that?
I have this in my httpd.conf, outside any other config statements:
ProxyRequests Off
ProxyPass /external/ http://www.external.com/onlyforme
ProxyPassReverse /external/ http://www.external.com/onlyforme
I am running Apache 2.2.
You need to add a couple of ProxyHTMLURLMap directives to the above, to inspect and rewrite any hard coded URL's in the returned HTML e.g.
ProxyRequests Off
ProxyPass /external/ http://www.external.com/onlyforme
ProxyHTMLURLMap http://www.external.com/onlyforme /external
<Location /external/>
ProxyPassReverse http://www.external.com/onlyforme
SetOutputFilter proxy-html
ProxyHTMLURLMap / /external/
ProxyHTMLURLMap /site_media /external/site_media/
</Location>
See also: http://wiki.uniformserver.com/index.php/Reverse_Proxy_Server:_mod_proxy_html
arober11's answer greatly helped solving my similar issue. I tried to narrow it down to the shortest set of rules possible, and there is my own configuration to have an Etherpad running at https://my-domain-name.wtf/pad :
<Location /pad>
ProxyPass http://localhost:9001 retry=0
# retry=0 => avoid 503's when restarting etherpad-lite
ProxyPassReverse http://localhost:9001
SetOutputFilter proxy-html
ProxyHTMLURLMap http://localhost:9001
</Location>
RewriteRule ^/pad$ /pad/ [R]

Infinite redirect when using mod_proxy_ajp ?

I'm trying to configure access from the root context of port 80 to redirect to my tomcat app. My config is set up like
<VirtualHost *:80>
ServerName localhost
ErrorLog /var/log/apache2/ajp.error.log
CustomLog /var/log/apache2/ajp.log combined
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/testApp
ProxyPassReverse / http://localhost/testApp
</VirtualHost>
Is this the correct way to do this ? It currently results in an infinite redirect loop.
Your ProxyPassReverse configuration is wrong. You want:
ProxyPass / ajp://localhost:8009/testApp
ProxyPassReverse / ajp://localhost:8009/testApp
The ProxyPass and ProxyPassReverse lines should have identical arguments.
Since you are changing the application path you may run into all sorts of additional issues including but not limited to:
cookies having the wrong path
embedded links using the wrong path
some libraries that place paths in custom HTTP headers using the wrong paths
Generally, life is a lot easier if you rename testApp to ROOT.