Nginx Reverse Proxy


Ubuntu 22 Nginx Reverse Proxy Commands
    1  sudo apt-get update -y
    2  sudo apt install curl
    3  curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
    4  sudo apt install nodejs
    5  node -v
    6  npm -v
    7  sudo apt update
    8  sudo apt install nginx
    9  sudo systemctl start nginx
   10  sudo systemctl status nginx
   11  sudo systemctl enable nginx
   12  sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.orginal
   13  sudo vi /etc/nginx/sites-available/default
   14  sudo vi /var/www/html/index.html
   15  pwd
   16  mkdir -p payment/public
   17  cd payment/
   18  cd public/
   19  vi payment.html
   20  cd ..
   21  vi server.js
   22  sudo chmod -R 755 /var/www/html/
   23  sudo nginx -t
   24  sudo service nginx restart
   25  sudo service nginx status
   26  node server.js

sudo vi /etc/nginx/sites-available/default
  server {
    listen 80;
    listen [::]:80;

    server_name pay.kishoreweb.com;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    location /payment {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;

        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
    }

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

create index.html file in /var/www/html/




    
    
    My E-Commerce Site
    


    

My E-Commerce Site

Product 1

Product 1

Description of Product 1

$19.99
Buy Now
Product 2

Product 2

Description of Product 2

$29.99
Buy Now
Product 3

Product 3

Description of Product 3

$39.99
Buy Now

© 2024 My E-Commerce Site. All rights reserved.

payment.html




    
    
    Payment Page
    


    

Payment Page






server.js
var http = require('http');
var fs = require('fs');
var path = require('path');

http.createServer(function (req, res) {
  if (req.url === '/payment') {
    fs.readFile(path.join(__dirname, 'public', 'payment.html'), function(err, data) {
      if (err) {
        res.writeHead(500, {'Content-Type': 'text/plain'});
        res.end('500 - Internal Server Error');
      } else {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(data);
      }
    });
  } else {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('SHIVAM welcomes you... here after all is good.');
  }
}).listen(3000, "127.0.0.1");

console.log('Server running at http://127.0.0.1:3000/');

Ubuntu 22 Nginx Reverse Proxy Deployment Steps

Step 1:


Step 2:


Step 3:


Step 4:


Step 5:


Step 6:


Step 7:


Step 8:


Step 9:


Step 10:


Step 11:


Step 12:


Step 13:

Step 14:

Step 15:

Step 16:

https://stackoverflow.com/questions/65582660/using-different-aws-credentials-in-bitbucket-pipeline-->