add subdomain for node.js application in DirectAdmin - node.js

On my VPS I host several laravel applications.
Subdomains are added using DirectAdmin and VirtualHost settings are done using the DirectAdmin Httpd.conf customization, like:
|*if SUB="cluego"|
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/cluego/public|
|*endif|
|*if SUB="ijsbrekerz"|
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/ijsbrekerz/public|
|*endif|
Now I want to add the subdomain for qruzzle:
|*if SUB="qruzzle"|
|?DOCROOT=/home/admin/domains/netwerkspel.nl/public_html/qruzzle|
|*endif|
But qruzzle is a node.js application, and in the qruzzle directory a server.js is running on port 3000.
Can anyone tell me how I can configure this in the easiest way? Do I need to set up a reverse proxy? Is that possible using DirectAdmin?

Related

Spring boot .jar to digital ocean droplet (Linux Ubuntu) :Web server failed to start. Port 80 was already in use

I have an Digitalocean Droplet (virtual private server) that has Ubuntu 18.04 running on it. I installed Apache Web Server and have my website running on it . It's open to traffic on HTTP port 80. My virtual host is setup at /var/www/MyDomainNameHere/public_html/ and I do have a custom domain name pointing to the IP.
I am trying to deploy/run a executable .jar that contains a Spring boot API. It has some basic GET/POST/DELETE HTTP requests. When I run the jar by
java -jar rest-service.jar
I get this error message
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 80 was already in use.
Does this mean the Apache Web Server that is open to Traffic on port 80 on this Digital ocean droplet won't let me run the API jar on the same server (The JAR loads up an Apache Tomcat embedded server, I set it to port 80 based on research)? Do I need to buy another droplet? Or can I maybe change the port number for the spring boot jar to something other than port 80? It's an API, so I need to be able to hit the end points
Yes, Apache Web Server using the port and you change your spring application 80 to any other port and use the reverse proxy in Apache Web server. here is the link to configure the reverse proxy
Apache as a Reverse Proxy with mod_proxy
So I will answer my own question. I googled and searched stackoverflow but most people were using the reverse proxy to direct traffic to their standalone embedded Tomcat server (most of time a Spring Boot app) which wasn't applicable to my situation.
However, I already had a static html website at alpizano.me hosted on Digital Ocean that I wanted to use as my Front-end, and only forward certain HTTP requests to my Spring Boot app, which was a REST API essentially.
So after installing Java and PostgreSQL on my DigitalOcean droplet, I SCP'd my JAR file (running ./mvnw clean package -Dmaven.test.skip=true to create it) to my server to a directory like, /var/myapp.
Then after researching for a few days and trying multiple things, I was able to figure out the combination that would allow me to view my website when navigating to alpizano.me, but still allow me to hit my API endpoints that were running on my server as-well, after I ran my jar via java -jar myapp.jar
So I basically had to set up my .conf file in the /etc/apache2/sites-available dir (I only used 1 virtual host for this project) as:
<VirtualHost *:80>
ServerName yourservername.com
DocumentRoot /var/www/yourservername.com/public_html
ProxyPreserveHost On
ProxyPass /api http://127.0.0.1:8080/
ProxyPassReverse /api http://127.0.0.1:8080/
</VirtualHost>
Notice the /api route for the routing that goes to the embedded Tomcat at port 8080 (you can't use port 80 or it will conflict with Apache Server already listening on port 80), else if it's just / , then it will not allow traffic to base website anymore (alpizano.me), which isn't what I wanted.
This wouldn't be needed if you just had a standalone app that you wanted to route traffic, then you could just use / as your route obviously. I saw other posts talking about forwarding the headers but that didn't seem to make a difference for me and I believe ProxyPreserveHost On takes care of that anyway
Good luck.
References:
https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

Reverse proxy using nginx on bluehost vps does not works with subdomains

I have bluehost VPS hosting on which I am hosting a node js app. I have configured my vps server and installed nginx on it. Now I am using the reverse proxy to redirect the domain.com to localhost:3000 which is running node js app. Now I have a second node js app that I want to run on sub.domain.com which is running on localhost:3001. I created the subdomain on bluehost then used the same reverse proxy config for sub.domain.com but it is not working.
and
?
I don't know why but adding
"proxy_redirect http://localhost:3001 http://sub.domain.com;"
in configuration file of subdomain fixed my problem :)
Solution Configuration

setting up nodejs on sharing host

how setting up nodejs on sharing host?
nodejs and git installed on my host and I access to ssh , but when I want to run my application , apache handle those routes.
I read some article but those said fix with httpd.conf and I don't access to httpd.conf
If you have the proper permissions you can forward all the traffic from port 80 that apache handles to the port that your node app is running. You can find examples on google if you search for keywords like apache, vhosts and reverse proxy.

Redirect a url to a local server

Is there any way to redirect a url to a local server?
Like http://example.com/1.js to http://localhost/1.js, without changing hosts file, using node js.
To configure apache on windows, refer this link proxy on windows
To configure apache on UBUNTU, refer this links
Apache2 reverse proxies
Apache proxy on ubuntu
In below code,
if i visit localhost/http-bind. it will hit localhost:5280/http-bind/
ProxyPass /http-bind http://localhost:5280/http-bind/

How to run sails.js application on port 80 with example?

I have to put sails.js in port 80, but apache is already using it. How can I put both (sails.js and apache) on the same port 80? I need it because in my company all the ports are blocked except for PORT 80. (This is a realtime application with nodejs and socket.io (websockets) and in the other side a php application). Thanks a lot
You have to run Sails on any free port (1337, for example) and use Apache with mod_proxy. Make sure it's loaded in Apache config, then your virtual host will be something like this:
<VirtualHost *:80>
ServerName www.youserver.com
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
</VirtualHost>
See mod_proxy documentation for more details.
Put nginx in front of sailsjs, and dump apache, or make apache run on a different port.
DigitalOcean has a great tutorial on doing this with two nodejs apps.. You can find it here.
I also wrote a blog post about it here
I do this on my server so i can run ghost blog, and sailsjs on the same server. This is how i have it setup.
NGINX Proxies blog.gorelative.com -> localhost:2368
NGINX Proxies gorelative.com -> localhost:1337
Just adapt the tutorial to proxy one domain to localhost:1337 for sailsjs, and add in the other hosts to host them normally.. or proxy the others to apache2, which probably is a waste of resources and not ideal.
AFAIK: With a bit more work your hosts don't even need to be on the same server. nginx can proxy to another server, and also do load balancing tasks.

Resources