Apache forward proxy by url parameter - apache

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

Related

How to put Qbittorrent webui port behind a https Apache2 server?

So basically, i have a apache2 server with https where i run some application
I am tring to using mod_proxy to proxy all traffic to url example.com/qb to [::1]:qb-webui-port.
So in /etc/apache2/mods-enabled/proxy.conf, i wrote:
ProxyRequests Off
<proxy *>
AddDefaultCharset off
Order Allow,Deny
Allow from all
</proxy>
ProxyPass /transmission http://[::1]:9091/transmission
ProxyPassReverse /transmission http://[::1]:9091/transmission
ProxyVia On
ProxyPass /qb http://[::1]:8112
ProxyPassReverse /qb http://[::1]:8112
The above is my similiar configuration for Transmission, i intended to do the same trick to Qbittorrent.
But it only returned plain html from example.com/qb.
In the firefox console i noticed that there were some request towards example.com/css, example.com/script etc.
This make me confused.
Can anyone provide some insights on this one?
Thx.
You missed the trailing slash on your addresses.
Here's my config file. I added a RewriteRule in case I enter the URL without the trailing slash. With these configs I haven't needed to modify anything else to get qb reverse proxy working.
I use the "/torrent/ subdir to access my qbittorrent webUI and it's listening on the 8080 port, so you should modify this in order to get your installation fully functional.
# Para qbittorrent
RewriteEngine on
RewriteRule ^/torrent$ "/torrent/$1" [R]
ProxyPass /torrent/ http://127.0.0.1:8080/
ProxyPassReverse /torrent/ http://127.0.0.1:8080/

Apache split wildcard sub-domain for ProxyPass

I have Apache config where I would need to split the http host domain which includes dashed subdomain and build a new path using these 3 of these matching groups in proxy pass or rewrite rule.
Example urls:
kube-test-selfservice.example.com/app/
kube-staging-selfservice.example.com/app2/
Would need to proxied to:
balancer://kubernetes/test/selfservice/app/
balancer://kubernetes/staging/selfservice/app2/
It is important that the test and selfservice in this example are captured as these values change. kube can be hardcoded for distinguishing this host under.
I currently only have basic proxy setup, have tried multiple regex rewrites, but as I am not very familiar with apache, would like some advice on that part.
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
ProxyRequests Off
ProxyPreserveHost On
AddDefaultCharset Off
<Proxy "balancer://kubernetes">
BalancerMember http://192.168.1.244:30001 route=node1 timeout=600
</Proxy>
ProxyPass / "balancer://kubernetes/"
ProxyPassReverse / "balancer://kubernetes/"
</VirtualHost>
Please try this, i try to run below and it worked :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^kube-([a-z0-9_]+.)?-([a-z0-9_]+.)?.example.com [NC]
RewriteRule "^/?(.*)" http://kubernetes/%1/%2%{REQUEST_URI} [R=301,L]
Used URL :
http://kube-test-selfservice.example.com/app/
URL Rewritten to :
http://kubernetes/test/selfservice/app/

Setting up mod_jk redirect in Hybris

I have installed apache httpd 2.2.15 in my app server. I need to get the login page(https://ip_address:9002/xxstorefront/xx/en/USD/login) when I hit on https://dev.xxyy.com/login. I have installed SSL certificate for my domain and set below redirect rules.
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
When I hit on https://dev.xxyy.com/login, I get below error,
Not Found 
The requested URL /login was not found on this server.
Apache/2.2.15 (CentOS) Server at dev.xxyy.com Port 443
When I hit on https://dev.xxyy.com, I get the apache default homepage.
Pls guide me how should I set the redirect rules.
Your configuration is invalid. Those two lines:
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
overwrite those two:
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
Rewite mechanism probably does not work at all:
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
I think this configuration should solve your problem:
<VirtualHost *:80>
ServerName dev.xxyy.com
ProxyPreserveHost On
ProxyPass / http://localhost:9001/xxstorefront/xx/en/USD/
ProxyPassReverse / http://localhost:9001/xxstorefront/xx/en/USD/
</VirtualHost>
<VirtualHost *:443>
ServerName dev.xxyy.com
SSLEngine on
// other SSL directives
ProxyPreserveHost On
ProxyPass / https://localhost:9002/xxstorefront/xx/en/USD/
ProxyPassReverse / https://localhost:9002/xxstorefront/xx/en/USD/
</VirtualHost>
It defines two virtual hosts which work as proxies and map all requests to xxstorefront/xx/en/USD/...:
http://dev.xxyy.com/(.*) → http://localhost:9001/xxstorefront/xx/en/USD/(.*)
https://dev.xxyy.com/(.*) → https://localhost:9002/xxstorefront/xx/en/USD/(.*)

Access CouchDB Fauxton UI from subdomain

Remote Server: Ubuntu 14.04 Headless
I've setup Couchdb v2.0.0 successfully, and can access it remotely via www.[mydomain].com:5984/_utils
I want to create a subdomain to access this URL, something like dbadmin.[mydomain].com
First, I created a subdomain of db.[mydomain].com (Here's the apache2 vhost config:)
<VirtualHost *:80>
ServerName db.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/
ProxyPassReverse / http://db.[mydomain].com:5984/
</VirtualHost>
Note: I have replaced [mydomain] with the actual domain ;P
I then created an A Record with my DNS Registrar as follows:
db A [PublicIP]
and then a SRV Record:
_db._tcp.db SRV 0 5 5984 db.[mydomain].com
and I test it by going to http://db.[mydomain].com/ on my laptop
Result: {"couchdb":"Welcome","version":"2.0.0","vendor":{"name":"The Apache Software Foundation"}}
So a success, I think. Now, I create the dbadmin subdomain. Apache2 vhost config:
<VirtualHost *:80>
ServerName dbadmin.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/_utils
ProxyPassReverse / http://db.[mydomain].com:5984/_utils
</VirtualHost>
Then another A Record:
dbadmin A [PublicIP]
Followed by another SRV Record:
_dbadmin._tcp.dbadmin SRV 0 5 5984 dbadmin.[mydomain].com
I test it by visiting http://dbadmin.[mydomain].com
Result: {"error":"unauthorized","reason":"You are not a server admin."}
I have spent far too many hours trying to suss out the proper way of doing this. I've tried all sorts of configurations, settings, DNS Records, changing couch's local.ini, proxy settings... You get the idea.
Please, elucidate how I can simply redirect a subdomain to either the server's public IP + port + path or the server's root domain + port + path?
I solved this with mod_rewrite in the VHost config:
<VirtualHost *:80>
ServerName dbadmin.[mydomain].com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Off
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://db.[mydomain].com:5984/
ProxyPassReverse / http://db.[mydomain].com:5984/
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/_utils
RewriteRule ^/$ /_utils/$1 [R,L]
It appears that I didn't even need the SRV Record, either. Groovy!
Can anyone succinctly explain to me what the Regex for this condition and rule are actually doing? I know at a basic level that it looks for /_utils in the query, and if not there, it puts it there...
The rule does however remove the protocol identifier 'http://' from the beginning of the URL, which is rather annoying... Can anyone explain why, and how to prevent that from happening?

Use modreverseproxy only if cookie is found

I have a site, lets call it example.com which is hosted on an Apache server listening in on port 80. I also am using modproxy at the moment to send traffic to another server that is listening in on port 8000. How can I only allow the traffic to be proxied if a PHPSESSID cookie is found? Here is my conf settings for the moment.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /private http://localhost:8000
ProxyPassReverse /private http://localhost:8000/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Some other things that I am also trying are:
<Proxy *>
Allow from all
</Proxy>
RewriteEngine On
RewriteRule %{HTTP_COOKIE} ^.*PHPSESSID.*$ [NC]
RewriteRule /private http://localhost:8000/$1 [P,L]