{"id":24650464,"url":"https://github.com/waseeftauqueer/local-node.js-deployment-with-secure-nginx-proxy","last_synced_at":"2025-12-31T00:03:49.736Z","repository":{"id":271564836,"uuid":"913857762","full_name":"waseeftauqueer/Local-Node.js-Deployment-with-Secure-NGINX-Proxy","owner":"waseeftauqueer","description":"Local Node.js Deployment with Secure NGINX Proxy  This project demonstrates how to set up a Node.js application locally with a secure NGINX reverse proxy. It walks you through deploying a Node.js app on your local machine while securing it with SSL using NGINX. The setup includes configuring NGINX to handle HTTPS requests and forward them to the No","archived":false,"fork":false,"pushed_at":"2025-01-08T13:57:14.000Z","size":753,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T18:15:02.134Z","etag":null,"topics":["nginx","nginx-docker","nginx-proxy","ssl-certificates"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waseeftauqueer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-08T13:42:19.000Z","updated_at":"2025-01-08T13:59:37.000Z","dependencies_parsed_at":"2025-01-09T01:16:38.534Z","dependency_job_id":null,"html_url":"https://github.com/waseeftauqueer/Local-Node.js-Deployment-with-Secure-NGINX-Proxy","commit_stats":null,"previous_names":["waseeftauqueer/local-node.js-deployment-with-secure-nginx-proxy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waseeftauqueer%2FLocal-Node.js-Deployment-with-Secure-NGINX-Proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waseeftauqueer%2FLocal-Node.js-Deployment-with-Secure-NGINX-Proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waseeftauqueer%2FLocal-Node.js-Deployment-with-Secure-NGINX-Proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waseeftauqueer%2FLocal-Node.js-Deployment-with-Secure-NGINX-Proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waseeftauqueer","download_url":"https://codeload.github.com/waseeftauqueer/Local-Node.js-Deployment-with-Secure-NGINX-Proxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244685703,"owners_count":20493310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx","nginx-docker","nginx-proxy","ssl-certificates"],"created_at":"2025-01-25T18:15:09.706Z","updated_at":"2025-12-31T00:03:49.729Z","avatar_url":"https://github.com/waseeftauqueer.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NGINX Proxy with Node.js and Docker\n\nThis project demonstrates how to set up a basic Express web server, containerize it using Docker, and proxy multiple instances of the app using NGINX. Additionally, the tutorial also covers how to secure your connection with SSL certificates.\n\n## Prerequisites\n\n- Node.js\n- Docker\n- NGINX\n- SSL certificates (for secure connection)\n\n## Table of Contents\n\n- [Project Overview](#project-overview)\n- [Setting Up the Express Web Server](#setting-up-the-express-web-server)\n- [Containerizing the Application](#containerizing-the-application)\n- [Creating Multiple Instances with Docker Compose](#creating-multiple-instances-with-docker-compose)\n- [Setting Up NGINX as a Reverse Proxy](#setting-up-nginx-as-a-reverse-proxy)\n- [Creating a Secure Encrypted Connection](#creating-a-secure-encrypted-connection)\n\n## Project Overview\n\nThis project demonstrates:\n1. A basic Express web server serving HTML files.\n2. Dockerizing the application.\n3. Running multiple instances of the app using Docker Compose.\n4. Using NGINX as a reverse proxy to balance requests across multiple app instances.\n5. Securing the connection using SSL certificates.\n\n## Setting Up the Express Web Server\n\n### Step 1: Create a Basic HTML File\nCreate a simple `index.html` file.\n\n### Step 2: Create the Express Server\n\nCreate a `server.js` file with the following code:\n\n```js\nconst express = require('express');\nconst path = require('path');\nconst app = express();\nconst port = 3000;\n\napp.use('/images', express.static(path.join(__dirname, 'images')));\n\napp.use('/', (req, res) =\u003e {\n    res.sendFile(path.join(__dirname, 'index.html'));\n    console.log(\"Request served by node app\");\n});\n\napp.listen(port, () =\u003e {\n    console.log(`Node app is listening on port ${port}`);\n});\n```\n\n### Step 3: Install Dependencies\n\nRun the following command to install dependencies:\n\n```bash\nnpm install\n```\n\n### Step 4: Run the Server\n\nRun the server with:\n\n```bash\nnode server.js\n```\n\n## Containerizing the Application\n\n### Step 1: Create a Dockerfile\n\nCreate a `Dockerfile` with the following content:\n\n```dockerfile\nFROM node:14\n\nWORKDIR /app\n\nCOPY server.js .\nCOPY index.html .\nCOPY images ./images\nCOPY package.json .\n\nRUN npm install\n\nEXPOSE 3000\n\nCMD [\"node\", \"server.js\"]\n```\n\n### Step 2: Build and Run the Docker Image\n\nBuild the Docker image:\n\n```bash\ndocker build -t myapp:1.0 .\n```\n\nRun the Docker container:\n\n```bash\ndocker run -p 3000:3000 myapp\n```\n\n## Creating Multiple Instances with Docker Compose\n\n### Step 1: Create `docker-compose.yaml`\n\nDefine multiple app instances in `docker-compose.yaml`:\n\n```yaml\nservices:\n  app1:\n    build: .\n    environment:\n      - APP_NAME=App1\n    ports:\n      - \"30001:3000\"\n  \n  app2:\n    build: .\n    environment:\n      - APP_NAME=App2\n    ports:\n      - \"30002:3000\"\n\n  app3:\n    build: .\n    environment:\n      - APP_NAME=App3\n    ports:\n      - \"30003:3000\"\n```\n\n### Step 2: Update the Server Code\n\nUpdate the `server.js` to include the app name in the logs:\n\n```js\nconst express = require('express');\nconst path = require('path');\nconst app = express();\nconst port = 3000;\n\nconst replicaApp = process.env.APP_NAME;\n\napp.use('/images', express.static(path.join(__dirname, 'images')));\n\napp.use('/', (req, res) =\u003e {\n    res.sendFile(path.join(__dirname, 'index.html'));\n    console.log(`Request served by ${replicaApp}`);\n});\n\napp.listen(port, () =\u003e {\n    console.log(`${replicaApp} is listening on port ${port}`);\n});\n```\n\n### Step 3: Build and Run Multiple Instances\n\nBuild and start the instances:\n\n```bash\ndocker-compose up --build -d\n```\n\n### Step 4: Check Logs\n\nCheck the logs to ensure the multiple instances are running correctly:\n\n```bash\ndocker-compose logs\n```\n\n## Setting Up NGINX as a Reverse Proxy\n\n### Step 1: Install NGINX\n\nInstall NGINX using:\n\n```bash\nsudo apt install nginx\n```\n\n### Step 2: Configure NGINX\n\nCreate an NGINX configuration file (`nginx.conf`) with the following content:\n\n```yaml\nworker_processes 1;\n\nevents {\n    worker_connections 1024;\n}\n\nhttp {\n    include mime.types;\n\n    upstream nodejs_cluster {\n        least_conn;\n        server 127.0.0.1:30001;\n        server 127.0.0.1:30002;\n        server 127.0.0.1:30003;\n    }\n\n    server {\n        listen 8080;\n        server_name localhost;\n\n        location / {\n            proxy_pass http://nodejs_cluster;\n            proxy_set_header Host $host;\n            proxy_set_header X-Real_IP $remote_addr;\n        }\n    }\n}\n```\n\n### Step 3: Test the NGINX Proxy\n\nEnsure NGINX is running and handling requests on port 8080.\n\n## Creating a Secure Encrypted Connection\n\n### Step 1: Generate SSL Certificates\n\nGenerate a self-signed SSL certificate using:\n\n```bash\nopenssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx-selfsigned.key -out nginx-selfsigned.crt\n```\n\n### Step 2: Update NGINX for SSL\n\nUpdate the NGINX configuration to use SSL:\n\n```yaml\nserver {\n    listen 443 ssl;\n    server_name localhost;\n\n    ssl_certificate /path/to/nginx-selfsigned.crt;\n    ssl_certificate_key /path/to/nginx-selfsigned.key;\n\n    location / {\n        proxy_pass http://nodejs_cluster;\n    }\n}\n```\n\n### Step 3: Restart NGINX\n\nRestart NGINX to apply the changes.\n\n---\n\n## Conclusion\n\nWith this setup, you have:\n- A basic Express web server.\n- Dockerized the application and run multiple instances.\n- Used NGINX as a reverse proxy for load balancing.\n- Secured the connection using SSL certificates.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaseeftauqueer%2Flocal-node.js-deployment-with-secure-nginx-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaseeftauqueer%2Flocal-node.js-deployment-with-secure-nginx-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaseeftauqueer%2Flocal-node.js-deployment-with-secure-nginx-proxy/lists"}