Apache Location regex is not matching paths - node.js

I'm just trying to point my apache server at a node.js app by changing the virtual host settings to use proxy settings and when I try to make the Block match all locations via It matches only urls with 1 level deep url paths. /example works but /example/damn does not work. So I tried changing the regex to Which is even overkill but I thought I'd try it, I've been trying a lot of other regex combinations but none capture the URLs. I might add that this regex above actually doesn't capture anything AT ALL, it just shows the index list for my site when I got the url. The only regex that works at all is "/*" but it doesn't go deeper than 1 url /path/anotherpath
I checked that my regex should be matching everything at https://regex101.com/ But still apache isn't capturing it.
here's me config
<VirtualHost *:80>
ServerName my.dev
ServerAdmin ireply#myleisure.com.au
DocumentRoot /home/ggg/Dropbox/host-root/var/www/myleisure.com.au
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy "*">
Require all granted
</Proxy>
<Location "(.*)*">
ProxyPass http://localhost:3000
ProxyPassReverse http://localhost:3000
</Location>
</VirtualHost>

Here is quote from Apache directive configuration documentation page
The directive limits the scope of the enclosed
directives by URL, in an identical manner to . However, it
takes a regular expression as an argument instead of a simple string.
Therefore, try using:
<LocationMatch "(.*)*">
ProxyPass http://localhost:3000
ProxyPassReverse http://localhost:3000
</LocationMatch>

Related

Running Traefik docker-proxy behind an apache server, redirecting/proxying some of the requests (or vice versa)

I have a Traefik-2 docker-compose-setup for dev (and one similar for prod) with multiple docker-compose projects containing multiple dc-images, each can be reached locally like this: https://docker-app1.docker-doamin1.loc, incl. HTTPS/SSL-Certs; "dns" via /etc/hosts.
This works like a charm, when the traefik-container is running and the apache is not (port conflict otherwise)
I also have some projects that can be run directly on a local apache (on ubuntu/debian) with configurations in /etc/apache2/sites-available/ like this:
<VirtualHost *:80>
ServerName apache-app1.apache-domain1.loc
DocumentRoot /path-to/apache-app1.apache-domain1.loc/public
<Directory /path-to/apache-app1.apache-domain1.loc/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
Fallbackresource /index.php
</Directory>
DirectoryIndex index.php index.html
</VirtualHost>
But only if the apache is running and the docker-traefik container ist not, again because of the conflicting 80/443
I need (or want) both Versions to run simultaneously.
My idea was to run the docker-traefik container on different ports (20080/20443) and redirect/ProxyPass from apache to that docker-proxy-container (the other way round would be okay too)
I tried (e.g.)this:
<VirtualHost *:443>
ProxyPreserveHost On
ProxyRequests Off
ServerName docker-app1.docker-doamin1.loc
ServerAlias www.https://docker-app1.docker-doamin1.loc
ProxyPass / https://docker-app1.docker-doamin1.loc:20443/
ProxyPassReverse / https://docker-app1.docker-doamin1.loc:20443/
</VirtualHost>
having
127.0.1.1 docker-app1.docker-doamin1.loc
in my /etc/hosts.
But it does not work. And it would be better in each case to have wildcards redirected like this: *.docker-doamin1.loc.
For now all of this is for a local dev environment, so security is not that relevant.
It would be great, if someone had some hints here.

How can I make a ProxyPass work for all pages without defining a new rule for each page

I'm very new to setting up apache configs. The docs don't make much sense to me, I have a node app running on a port that functions as a website, but I want to be able to connect to it with my domain. I've been looking around and figured I need to use a ProxyPass to redirect traffic from port 443 (https) to the port the app is running on (I already use apache for other stuff so I didn't want to switch). And it works generally, but is there a way to make only a single ProxyPass rule that will handle all pages (e.g. I go to https://example.com/ it will use https://localhost:4450/ and if I go to https://example.com/example it will use https://localhost:4450/example and for all other pages).
I would think I need a RewriteRule, but I don't really understand how I can get the page (whatever is after the first / or none) using it.
You simply run apache as a reverse proxy here is an example configuration:
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/file.pem
ProxyPreserveHost On
ServerName localhost
ProxyPass / http://0.0.0.0:4450/
ProxyPassReverse / http://0.0.0.0:4450/
</VirtualHost>
and you have to enable the proxy modules like that
a2enmod proxy
a2enmod proxy_http

Apache reverse proxy for Node sever

I have a apache-based server running on https://example.com and inside of it a node application running on port 3000. Requests can be succesufully sent to https://example.com:3000, however, since I am planning to run multiple applications, I would like to set-up some reverse proxy for different applications. In order to do it I added the following lines to the apache conf file:
<VirtualHost *:80>
ServerAdmin foo#example.com
ServerName example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /myapp1>
ProxyPass http://localhost:3000
ProxyPassReverse http://localhost:3000
</Location>
<Location /myapp2>
ProxyPass http://localhost:3010
ProxyPassReverse http://localhost:3010
</Location>
</VirtualHost>
This approach does not seem to be working as requests to https://example.com/myapp1 are not returning anything.
Update
After some debugging, I found out that the .conf file was actually being included inside a <VirtualHost> tag which was triggering the error (nested <VirtualHost> tags). Now I simply have the following:
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /myapp1>
ProxyPass http://127.0.0.1:3000
ProxyPassReverse http://127.0.0.1:3000
</Location>
<Location /myapp2>
ProxyPass http://127.0.0.1:3010
ProxyPassReverse http://127.0.0.1:3010
</Location>
Now when I hit https://example.com/myapp1 I get Not Found - 500 Internal Server Error. Which at least show that routing is being recognized. Any ideas how to proceed with the debugging process?
Any ideas how to properly set up it
I finally managed to fix my problem last week. The following line of code was missing from my reverse proxy configuration:
SSLProxyEngine on
Thanks for all the help.

Apache Virtual Proxypass nodejs application - Empty page

I'm running an apache server with a proxypass for my node js application.
Here's what I got in my virtualhost :
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:3333/
ProxyPassReverse / htttp://127.0.0.1:3333/
<Location />
Order allow,deny
Allow from all
</Location>
Basically I want to redirect every request to my nodejs application and it works when I use the direct link.
My issue is when I try to reach it using tier app ( e.g Postman ) it doesn't return my html page. I need tier apps & site to get the meta tags to share on social networks (FB, TW, ...).
My vhost knowledge is really weak, I'd be really grateful if someone could help me on this case.
Thanks !
This should work just fine
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3333/
ProxyPassReverse / htttp://127.0.0.1:3333/
</VirtualHost>

Using .htaccess to mask a domain?

So here's the scenario:
The domain I have is www.abc.com and I want to point it to (which belongs to another company).
Question: How would I use .htaccess to forward and mask the url so that it stays as www.abc.com?
In terms of security, is there any point in buying a digital certificate for www.abc.com?
You could uh, run it through a proxy, which will TOTALLY mask it.
You put this in your httpd.conf file, not the .htaccess:
<VirtualHost *:80>
ServerName www.abc.com
ServerAlias abc.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://site-you-want-2-show.com:80/
ProxyPassReverse / http://site-you-want-2-show.com:80/
<Location />
Allow from all
</Location>
</VirtualHost>
You can try with ProxyPreserveHost both On and Off, and testing if the images display properly and the addresses of objects show your domain instead.
WARNING: This is not legal if you do not have explicit permission from the company you are trying to show's website. Perhaps you can then just make your homepage an iFrame.
As for certificates: It can be done, see here: http://ssl-proxy.plz.re (short-url)
.htaccess files cannot "mask" a domain but could use a reverse proxy if the module is installed.
In most case, the "masked" website will refer to full urls and the "mask" will not work for long.
See what #mesh proposed.

Resources