Apache 2.4 Reverse proxy to Node Application on Docker - node.js

I have a dedicated server on Apache 2.4 and I made a node application which is running on a Docker container and listenning on the port 5847
So I am trying to configure my apache to make a reverse Proxy to http://my.url.com:5847 on a Debian 8 machine
When I made this, I have the start page of apache "It Works" but not my application. Of course, If I check http://my.url.com:5847 in my navigator, it works fine, but why my reverse Proxy doesn't work?
This is my my.url.com.conf apache config file :
<VirtualHost *:80>
ServerAdmin hello#my-url.com
ServerName my.url.com
ProxyPass "/" "http://my.url.com:5847/"
ProxyPassReverse "/" "http://my.url.com:5847/"
</VirtualHost>
So I'm quite desesperate, I also tried to add
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
I also tried with Required all granted, I tried with the <Location /> directive, with ProxyRequests Off and On too but nothing is working and I don't understand what is going wrong...
Can you help me please? What am I doing wrong?

This wks for me (apache 2.4, node.js runs in 192.168.32.35 on port 3003), on Debian 8
<VirtualHost feed.mydomain.net:3003>
ServerName feed.mydomain.net
ServerAdmin yves#mydomain.com
DocumentRoot /var/www/html
<Location />
ProxyPass http://192.168.32.35:3003/
ProxyPassReverse http://feed.mydomain.net:3003/
Order allow,deny
Allow from all
</Location>
LogLevel trace1 ssl:warn rewrite:trace1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Okay, so ... I think I found my error, I was writing an conf archive without .conf extension in sites-enabled and that's why apache wasn't taking my configuration... I re-made my configuration file in sties-enabled and then enabled it from apache with a2ensite my.url.com.conf and now it works...
Sorry for the bas question, nothing to do with reverse proxy!

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.

Can not access api when set up Node.js app with Apache on ubuntu 20.04

I'm deploying my node.js app with apache on ubuntu following https://imstudio.medium.com/set-up-a-node-js-app-for-a-website-with-apache-on-ubuntu-18-04-e0323c333c20.
This node.js app is listening on port 4000. I put it in directory/var/www/html/api and start it by pm2.
After deployment, I tested my api and found that only my home url www.myweb.tk/api works, and other sub urls, for examplewww.myweb.tk/api/location, does not work.
Here is my conf file:
<VirtualHost *:80>
ServerName myweb.tk
ServerAlias www.myweb.tk
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /api>
ProxyPass http://127.0.0.1:4000/
ProxyPassReverse http://127.0.0.1:4000/
</Location>
</VirtualHost>
Can anyone tell me how to make other urls works? Thank you in advance.
I has same issue, but with nginx, i solved it by adding /api to proxy
Try to pass http://127.0.0.1:4000/api
UPD:
Or search for something like request url varible in Apache

How can I run NodeJS and Apache together with an Apache virtual host file on Centos8?

I have my NodeJS application running on example.com:3000. Obviously, this would be unpresentable to have to tell a user to type in :3000. I want it running on example.com, and I cannot set Node to :80 since my Apache PHP front end is on :80.
I am running CentOS 8. I created a file called proxy.conf in /etc/httpd/conf.d and dropped the following lines in it.
<VirtualHost *:80>
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
ProxyRequests On
ProxyPass / http://localhost:3000
ProxyPassReverse / http://localhost:3000
</VirtualHost>
But, it's just going to my regular non node page.
The question is, how does apache know you when you want the PHP server, or when you want the Node server. You need to split them by ServerName.
You need a ServerName attribute so that apache knows to send that VirtualHost to the other process.
<VirtualHost *:80>
// PHP Server
ServerName example.com www.example.com
</VirtualHost>
<VirtualHost *:80>
// Node Server
ServerName node.example.com
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
ProxyRequests On
ProxyPass / http://localhost:3000
ProxyPassReverse / http://localhost:3000
</VirtualHost>
Additionally, you will have to put node.example.com within DNS.

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 reverse proxy setup (for node.js application) not working?

What I am trying to do
After running the command (export PORT=3000 && node server.js) my node.js app (StackEdit) is served at: http://example.com:3000/.
The command (export PORT=80 && node server.js) wouldn't work considering that Apache already uses port 80 on the server.
As I am new to Node.js, an easy way to make the node.js app available at http://example.com/ (i.e. port 80) would be to set up Apache as a reverse proxy.
Here's what I've tried
In /etc/apache2/sites-available/example.com.conf
Trial (1):
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com/public
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/editor.aahanblog.com/logs/access.log combined
ProxyPass / http://example.com:3000/
ProxyPassReverse / http://example.com:3000/
</VirtualHost>
This simply shows the directory listing for the public directory. So, in this case the requests aren't reaching the node.js app.
Trial (2):
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /var/www/example.com/public
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /var/www/example.com/public>
ProxyPass http://mydomain:3000/
ProxyPassReverse http://mydomain:3000/
</Location>
</VirtualHost>
This doesn't work either. It takes me to some default apache page.
What I am missing here?
Change your Location directive as
<Location /> from <Location /var/www/example.com/public>
basically, Location directive is a prefix of the path component of the URL

Resources