How to deploy Node.JS application on Apache server? - node.js

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.

Related

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

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.

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>

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>

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