Apache reverse proxy setup (for node.js application) not working? - node.js

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

Related

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.

Not able to access other folder rather than node.js app

I have deployed an angular universal app on port 4000 and I have used a reverse proxy to make it live on port 80.
Application Path:/var/html/www/eduglobe/eduglobe/ (this path i access as domainname.com)
But I am not able to access Below path:/var/html/www/test/index.html ( This I am not able to access at domainname.com/test/index.html)
php and node.js server working fine.
Code for site-enabled 000-default.conf
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ServerName demo.eduglobe.in
DocumentRoot /var/www/html/eduglobe/eduglobe
<Location />
ProxyPreserveHost On
ProxyPass http://127.0.0.1:4000/
ProxyPassReverse http://127.0.0.1:4000/
</Location>
Have you enabled proxy_http?
The followings works for me!
Check that the Location directive points to the folder that hosts the app which is not the DocumentRoot (/) of the site enabled.
DocumentRoot /var/www/html/
<Location /demo>
ProxyPreserveHost On
ProxyPass "http://127.0.0.1:8080/"
ProxyPassReverse "http://127.0.0.1:8080/"
</Location>

Host multiple asp.net core web application under a single linux server

I am new to asp.net core. I read the whole Microsoft official document and able to host the application in Linux Apache server. But I want to host multiple asp.net core web applications under a single IP Address. Please, anyone have the solution post here.
Thanks in Advance
The official document shows us a way to use Apache as a reverse proxy :
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.example.com
ServerAlias *.example.com
ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
</VirtualHost>
Basically, this configuration will make Apache listens on *:80 and proxy any HttpRequest whose ServerName equals www.example.com to http://127.0.0.1:5000/.
This is how Apache used as an proxy to ASP.NET Core works.
As for your question, suppose you have two asp.net core web applications:
the first one is called WebApp1 and listens on 0.0.0.0:5000 .
and the other is called WebApp2 and listens on 0.0.0.0:6000 .
Your Apache server listens on 0.0.0.0:80. For any incoming http request,
when Host equals www.webapp1.org, proxy this request to 0.0.0.0:5000
when Host equals www.webapp2.org, proxy this request to 0.0.0.0:6000
So you could add two proxies :
proxy 1 :
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.webapp1.org
ServerAlias *.webapp1.org
ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
CustomLog ${APACHE_LOG_DIR}webapp1-access.log common
</VirtualHost>
proxy 2 :
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:6000/
ProxyPassReverse / http://127.0.0.1:6000/
ServerName www.webapp2.org
ServerAlias *.webapp2.org
ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
CustomLog ${APACHE_LOG_DIR}webapp2-access.log common
</VirtualHost>

Apache 2.4 Reverse proxy to Node Application on Docker

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!

How to deploy Node.JS application on Apache server?

I am developing node.js application and wants to deploy on apache server and run with https url only.
There is following url scheme I would like to configure on server.
https://example.com runs node js application on 1000 port from /home/main/public_html/ directory.
https://example.com:1335 runs node js application from /home/main/public_html/stagging/ directory.
https://example.com:4234 runs node js application from /home/main/public_html/development/ directory.
I want to achieve this type of url output from server.
I tried following way to achieve this but it display just directory listing only. I want to execute nodejs application.
<VirtualHost *:80>
ServerAdmin webmaster#domain.com
ServerName sub.domain.com
ProxyRequests Off
#Executes code from main directory
<Proxy https://whizbite.com:1000>
Order deny,allow
Allow from all
ProxyPreserveHost off
ProxyPass https://localhost:8080/
ProxyPassReverse https://localhost:8080/
</Proxy>
#Executes code from staging directory
<Proxy https://whizbite.com:1335>
Order deny,allow
Allow from all
ProxyPreserveHost off
ProxyPass https://localhost:8080/staging/
ProxyPassReverse https://localhost:8080/staging/
</Proxy>
#Executes code from development directory
<Proxy https://whizbite.com:4234>
Order deny,allow
Allow from all
ProxyPreserveHost off
ProxyPass https://localhost:8080/development/
ProxyPassReverse https://localhost:8080/development/
</Proxy>
</VirtualHost>
I really don't know how to achieve above url scheme by modification of apache configuration.

Resources