If you use LiteSpeed, you can run NodeJS project as a PHP project.
Step 1: Add a domain (example domain.com) to your server
You need to:
- Create a folder to upload your code. Or create by Cyberpanel admin tool (recommend).
- Add new DNS record (A) from domain to your server IP
Step 2: Modify the vhosts file:
Method 1: Edit vhosts file
You can edit on Cyberpanel (domain.com:8090) -> Websites -> domain.com -> vHost Conf. Or open vhosts by SSH.
(if forgot cyberpanel password, type adminPass newpasshere
in terminal)
My vhosts file in: /usr/local/lsws/conf/vhosts/domain.com/vhost.conf
Replace all with this content:
docRoot $VH_ROOT/public_html/projectfolder/dist (folder contain your start JS file)
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails admin@gmail.com
enableGzip 1
enableIpGeo 1
extprocessor staging {
type proxy
address 127.0.0.1:80
maxConns 100
env NODE_ENV=production
initTimeout 60
retryTimeout 60
respBuffer 0
}
context / {
type appserver
location /home/domain.com/public_html/projectfolder/dist
binPath /usr/bin/node
appType node
startupFile main.js
appserverEnv 1
maxConns 2000
rewrite {
enable 1
}
addDefaultCharset off
}
vhssl {
keyFile /etc/letsencrypt/live/domain.com/privkey.pem
certFile /etc/letsencrypt/live/domain.com/fullchain.pem
certChain 1
enableECDHE 1
renegProtection 1
sslSessionCache 1
enableSpdy 15
enableStapling 1
ocspRespMaxAge 86400
}
This configs also can be made in LiteSpeed admin control panel.
Method 2: Config in LiteSpeed control panel
Follow this guide: https://openlitespeed.org/kb/setting-up-name-based-virtual-hosting-on-openlitespeed/
Step 3: Config listener on port 80
Method 1: Edit config file
You can make config in /usr/local/lsws/conf/httpd_config.conf
(your config file may be in other folder) file as:
listener Default {
address *:80
secure 0
map domain.com domain.com:3000
map domain2.com domain2.com
map domain3.org domain3.org
}
Method 2: Setting on LiteSpeed admin control-panel:
Login to LiteSpeed admin: domain.com:7080
(if you forgot LiteSpeed admin pass, you can find in file: usr/local/lsws/admin/misc/admpass.sh
)
Go to Listeners-> default (port 80)-> Virtual Host Mappings -> domain.com. Select Virtual hosts, then change Domain*: domain.com:3000
Then restart your server
Now, when you type http://domain.com (your domain) to browsers. Frontend run on port 80 or 443. Backend auto run your app on port 3000 (or any port you custom). Remember, node was install on your server. Check it in: /usr/bin/node file.
Read more how to config OpenLiteSpeed as Load Balancer: https://openlitespeed.org/kb/use-openlitespeed-as-a-load-balancer/