hosting nodejs code in Apache Tomcat server - node.js

Is it possible to host a node.js application on Apache tomcat server and then expose an https url from it? I would like to access the https url from other machines.

Related

.Net Core not handling requests when defined in subdomain folder

I have a Linux Centos v7.9 with Apache installed. I published my web project to the server. For the backend I set it on port 90 and created a configuration file for apache with proxy server (to redirect to another port 31031, where .net 5 is listening and handling the requests. This works fine when I request my server ip with port 90. But when I wanted to set the backend as subdomain like api.domain.com and modified the configuration file, .net 5 is not handling the request anymore. When I request api.domain.com I see folder structure. What did I miss?
Here is the .conf file:
Service file:
Subdomain from cpanel:
Thanks.

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

Running both Node.js and Apache on the same domain and "URL"

Is it possible to run Both node and Apache on the same domain without adding the port in the URL ?
and serve both on the same page, i already have node running on port 8443 and Apache on port 433 and they both work fine but i need to specify in the link the port "8443" to access node which is not what i want,
i want to serve both on the same URL if possible without adding the port to the URL.
You can use Apache reverse proxy
Add this configuration to your apache conf.
ProxyPass "/nodeapp" "http:/localhost:8443"
You can access node application by http://www.example.com/nodeapp
A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from server. These resources are then returned to the client as if they originated from the web server itself.
You can set an nginx proxy before them and separate routes to apache or node.
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

node js installation on Apache HTTP server (centOS)

I'm working at a project in school that includes Apache server.
All i need to do right now to start working with the server is create An index file (html, ph) at my folder on the server (inside the public_html) and the server will return that page.
but the thing is that I want to write the server with nodejs.
I have already manage to install node on the server but I know how to ignore the Apache server and start working with node.
I read about that and I saw that i need to start node on a different port? or use proxy?
but I really don't know that much about servers.
You can use apache as proxy for nodejs https://httpd.apache.org/docs/2.2/mod/mod_proxy.html.
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
Or, if you want to run the nodejs not from root directory of server
ProxyPass /mynodejsproject http://localhost:3000/
ProxyPassReverse /mynodejsproject http://localhost:3000/
For example, nodejs application listens on 3000 port, apache on 80 port, and it proxies requests to nodejs application.
But i recommend you to use nginx as proxy for nodejs application, this is the config i used in my projects https://github.com/vodolaz095/hunt/blob/master/examples/serverConfigsExamples/nginx.conf
service apache2 stop Stops your apache server (It works on 80 port default)
Also there is a good tool for nodejs ,you will able to manage your nodeJS server(you can give 80 port now) like services with forever on nodeJS.(I assumed you know how to creating your nodejs http server)

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/

Resources