Hello Friends,
Welcome To Infinitbility!
In this Article, we deploy nodejs application subdirectory level in apache ubuntu server. here you get complete tutorial to deploy, setup, and run node js project in apache server.
let’s start with subdirectory.
what is Subdirectory url level?
Some people also say sub url or custom url. subdirectory come after core domain.
Take below example.

here https://infinitbility.com is core domain & category is a subdirectory url.
Install Node
here we are installing node version 10. you can also on below curl command.
- go to root dir on your ubuntu server.
1cd ~
- download node nodesource setup using curl command.
1curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
- run downloaded nodesource setup of node.
1sudo bash nodesource_setup.sh
- install nodejs on your server.
1sudo apt-get install -y nodejs
- check node version.
1node -v
- check npm version.
1npm -v
Install pm2
Now we will install PM2, which is a process manager for Node.js applications. PM2 provides an easy way to manage and daemonize applications (run them as a service).
We will use Node Packaged Modules (NPM), which is basically a package manager for Node modules that installs with Node.js, to install PM2 on our app server. Use this command to install PM2:
1sudo npm install -g pm2
Install Apache2
- install apache2 on your ubuntu machine.
1sudo apt-get install apache2
Next thing we need to proxy all requests incoming on port 80 through the URL of a node.js application to the running local node.js process. For this, we need to install/enable mod_proxy and mod_proxy_http modules on the Apache server :
1sudo a2enmod proxy
1sudo a2enmod proxy_http
Setup node project
put your node project code on html directory.
- go to html directory.
1cd /var/www/html/
Assuming you guys know to put code on the ubuntu server. ( if not comment on the post we will definitely create a tutorial. )
setup virtual host
- go to apache conf dir.
1cd /etc/apache2/sites-available/
- you can also create a separate conf file for your project but here explaining with the default conf file.
1<VirtualHost *:80>2 ServerAdmin [email protected]3 ServerName example.com4 ServerAlias www.example.com5 DocumentRoot /var/www/html/example.com6 <Directory />7 Options -Indexes +FollowSymLinks8 AllowOverride None9 Require all granted10 </Directory>1112 # subdirectory is your custom url13 ProxyRequests On14 ProxyPass /subdirectory http://example.com:8080151617 ErrorLog ${APACHE_LOG_DIR}/error.log18 CustomLog ${APACHE_LOG_DIR}/access.log combined19</VirtualHost>
- enable sites ( when disable )
1sudo a2ensite 000-default.conf
- restart your apache server
1sudo service apache2 restart
Run node project and check url
- go to application folder and run below command
1pm2 start server.js
Similarly, we can configure multiple apps using separate ports. The idea is quite simple, we use different ports to configure multiple apps without having to change the original URL.
Looking to setup react aaplication to setup on apache serevr?.
check below link.
https://infinitbility.com/deploy-react-application-on-ubuntu-apache
Thanks for reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.