DEV Community

Pierangelo
Pierangelo

Posted on

1 1

Using NodeJS App with Apache

How setting Apache2 using proxy for expose a NodeJS app.

First install apache2:

apt update

apt install apache2

install nodejs e npm

apt install nodejs

apt install npm

copy your app in /var/www/demo

here a repo to my demo app if you want use it:

https://github.com/pierangelo1982/nodejs-experiment/tree/master/06%20-%20show_hostname

install pm2

npm install -g pm2

we use pm2 for start a daemon of our app, and for enable an autostart in case of reboot of our machine.

from your terminal go into the root folder of the app

cd /var/www/demo

and launch the command:

pm2 start app.js

after that we must config an automatic start in case of reboot:

so launch this command:

pm2 startup systemd

and copy the env that will be print and paste it in the terminal, in my case is this:

sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pierangelo — hp /home/pierangelo

now we go to settings apache2
as first things we must enable two modules:

proxy

proxy_http

so from terminal launch this:

a2enmod proxy

a2enmod proxy_http

after that go in /etc/sites/available and create a file named myapp.conf

myapp.conf

<VirtualHost *:80>
 ServerName node.mysite.it 
 ProxyPreserveHost on
 ProxyPass / http://localhost:3000/
 ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

check carefully, in ProxyPass and ProxyPassReverse you mast show the localhost with the port that you use in your nodejs app.

after that enable your virtualhost:

a2ensite myapp.conf

and restart apache2

service apache2 restart

now you should see your app running on your domain address.

Vedi Tutorial Here

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more