Apache Proxy ProxyRemote expression not catching - regex

I've set up an Apache as a forward proxy. Actually it's not doing any proxying itself but forwards everything to the proper proxy.
However some forwarding with ProxyRemote is not working. The Apache is supposed to forward traffic for certain URL to a certain proxy.
If I use
ProxyRemote "*" "http://realproxy:8080"
everything works.
If I use expressions for the actual URLs that should be forwarded nothing is forwarded.
ProxyRemote "*some-site.com/*" "http://realproxy:8080"
ProxyRemote "*another-site.com/*" "http://realproxy:8080"
Any ideas why the expressions aren't catching?

Related

How to set routing between nginx locations based on regex with wildcard

I have some http api behind nginx, and i want to make filter requests to API based on requests parameters value. Parameters are passed directly in url like
https://api.com/api/v1/action?param1=value1&param2=value2&etc...
Lets assume that i want to filter requests with some value of param2 to some other url.
I thought that it will be easy like
location ~* /api/.*param2=somevalue.* { #location; }
But nginx cant find the match even if there is no alternative location at all.
I'm confused. Are these wildcards are truly wildcards, or I miss something? But what?
I already tried escaping and different modifiers but no luck. :(

AWS Application Load Balancer redirect all www and non http to https://

I have a rule setup to redirect all traffic from http to https
How can I also redirect http://www to https://? As far as I can tell the {host} variable contains www and I cant remove it.
In fact it's pretty simple
Instead of writing {host} in your rule just put the name of your website.
So, for example, it will look like this :
https://example.com:443/#{path}?#{query}

How to write regex for apache ProxyPassMatch to reverse proxy API calls

I have an angular 4 web application which is hosted on apache 2.4. The application makes use of an API written in nodejs javascript running over express. Both the website and the API service are running on the same machine but on different ports. The website is on port 80 and the API service is listening on port 9000.
I would like to set up apache to do reverse proxy for all the API calls.
For example, any url that contains /api/ I want it rewritten by apache to point to the API url:port. If I use ProxyPass like the following lines, the redirect works fine:
ProxyPass "/api/V1/systeminfo" "http://localhost:9000/api/V1/systeminfo"
ProxyPassReverse "/api/V1/systeminfo" "http://localhost:9000/api/V1/systeminfo"
What I do not know how to do, is to use the ProxyPassMatch directive and create a regular expression so that any url that contains /api/ is redirected to http://localhost:9000/api/.....
I tried the following but it does not work:
ProxyPassMatch "^/api.*$" "http://localhost:9000/$1"
ProxyPassReverse "^/api.*$" "http://localhost:9000/$1"
Neither does the following:
ProxyPassMatch "^/.*?/api.*?/v[0-9]+/(.*)$" "http://localhost:9000/$1"
ProxyPassReverse "^/.*?/api.*?/v[0-9]+/(.*)$" "http://localhost:9000/$1"
Any help would be appreciated. My regex skills are lacking!
Note: obviously 'localhost' can be an IP address or a domain, I am using it in the example for simplicity.
Many thanks!
Edit: I corrected the first example to use .* instead of just * as per Alex's comment.
I solved the problem. The correct way to do reverse proxy with apache on the above example is the following:
ProxyPassMatch "/api(.*)" "http://localhost:9000/api$1"
ProxyPassReverse "/api(.*)" "http://localhost:9000/api$1"
I knew the multiple regex examples I was trying were correct, as I was testing them with https://regex101.com/, but I was hard coding the second part of to a particular route in order to eliminate the issue of the second part being incorrect, but for some reason it does not like that. Once I understood that the (.*) part of the regex is the first capture group and used it as $1 in the second part, it all worked.
I hope I clarified the answer enough and it is useful to someone else.

Create AWS Application Load Balancer Rule which trim off request's prefix without using additional reverse proxy like nginx, httpd

Basically, I have a couple of services. I want to forward every requests with prefix "/secured" to server1 port 80 and all other requests to server 2 port 80. The problem is that on server1, I am running service which accept the request without "/secured" prefix. In other words, I want to forward every requests such as "http://example.com/secured/api/getUser" to server1 as "http://example.com/api/getUser" (remove /secured from request' path).
With AWS ALB, currently the request is sent as http://example.com/secured/api/getUser; which forces me to update my server1's code so that the code handles requests with /secured prefix which doesn't look good.
Is there any easy way to solve this with ALB?
Thanks.
I can confirm that this is unfortunately not possible with the ALB alone - and I agree it really should be.
AWS states:
Note that the path pattern is used to route requests but does not
alter them. For example, if a rule has a path pattern of /img/*, the
rule would forward a request for /img/picture.jpg to the specified
target group as a request for /img/picture.jpg.
I had the same issue, and as Mark pointed out, you can use reverse proxy on your server and do something like this (this is Nginx configuration):
server {
listen 80 default_server;
location /secured/ {
proxy_pass http://localhost:{service_port}/;
}
}
This will strip the /secured part and proxy everything else to your service. Just be sure to have the trailing / after the service port.

Apache mod_proxy ProxyPassMatch Regex

I've setup Apache as a reverse proxy for a non public backend server, using mod_proxy. However one of my ProxyPassMatch directives always returns 404:
ProxyPassMatch ^/app/files/public/orders/06_production/jobs/([a-zA-Z0-9\-]+)/Preview%20PNG/(V[0-9]+)/([a-zA-Z0-9_\-]+.png)$ http://192.168.2.42/app/files/public/orders/06_production/jobs/$1/Preview%20PNG/$2/$3
This should match an incoming request like this:
/app/files/public/orders/06_production/jobs/P116087/Preview%20PNG/V1/bla.png
Any idea what's wrong with my Regex?
Figured it out:
ProxyPassMatch "\A/app/files/public/orders/06_production/jobs/([a-zA-Z0-9\-]+)/Preview PNG/(V[0-9]+)/([a-zA-Z0-9_\-]+.png)\z" "http://192.168.2.42/app/files/public/orders/06_production/jobs/$1/Preview PNG/$2/$3"