Wednesday, February 9, 2022

How To Deploy Node.js Application With Nginx in Rocky Linux 8

 in This Tutorial you will Learn " How To Deploy Node.js Application With Nginx in Rocky Linux 8"
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
NPM – or "Node Package Manager" – is the default package manager for JavaScript's runtime Node.js
_________________________________________________________________________________________
Server - Os:  Rocky Linux 8.5  64Bit      | IP -192.168.1.60                 | Hostname - server.yourdomain.com
_________________________________________________________________________________________
cat /etc/system-release ; hostname ; hostname -I ; sestatus
dnf groupinstall "Development Tools" -y
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
dnf install nodejs -y
npm --version ; node --version

Creating a sample Node.js Application -
nano first.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World/n');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');

npm install pm2@latest -g
pm2 start first.js
pm2 stop  first.js
netstat -tlpn

dnf makecache ; dnf install nginx -y
nano /etc/nginx/conf.d/yourdomain.conf
server {
    listen 80;
    server_name www.yourdomain.com;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://127.0.0.1:8080;
    }
}
systemctl restart nginx ; systemctl enable nginx ; systemctl status nginx
firewall-cmd --permanent --add-service={http,https} ; firewall-cmd --reload
echo "192.168.1.60 www.yourdomain.com"  >> /etc/hosts
www.yourdomain.com
_________________________________________________________________________________________



No comments:

Post a Comment