{"id":24554119,"url":"https://github.com/korngsamnang/master-nginx","last_synced_at":"2025-07-12T07:04:16.833Z","repository":{"id":267884795,"uuid":"902381273","full_name":"korngsamnang/master-nginx","owner":"korngsamnang","description":"The core concepts of nginx.","archived":false,"fork":false,"pushed_at":"2024-12-13T02:11:21.000Z","size":1624,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-23T17:13:29.247Z","etag":null,"topics":["load-balancer","nginx"],"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/korngsamnang.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":"2024-12-12T13:06:06.000Z","updated_at":"2024-12-14T07:57:47.000Z","dependencies_parsed_at":"2024-12-13T03:19:24.623Z","dependency_job_id":"29c6932a-3ca2-4701-832f-7bfec3fd9205","html_url":"https://github.com/korngsamnang/master-nginx","commit_stats":null,"previous_names":["korngsamnang/master-nginx"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/korngsamnang/master-nginx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korngsamnang%2Fmaster-nginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korngsamnang%2Fmaster-nginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korngsamnang%2Fmaster-nginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korngsamnang%2Fmaster-nginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/korngsamnang","download_url":"https://codeload.github.com/korngsamnang/master-nginx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korngsamnang%2Fmaster-nginx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264952204,"owners_count":23688035,"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":["load-balancer","nginx"],"created_at":"2025-01-23T02:17:32.701Z","updated_at":"2025-07-12T07:04:16.812Z","avatar_url":"https://github.com/korngsamnang.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nginx Load Balancing with Docker Compose\n\nThis project demonstrates a setup where Nginx acts as a load balancer for three Node.js applications running in Docker containers. The configuration includes HTTPS support with self-signed SSL certificates.\n\n\u003e Process flow diagram\n\u003e ![](diagram.png)\n\n---\n\n## Features\n\n-   **Load Balancing**: Distributes requests among three Node.js apps using the `least_conn` method.\n-   **HTTPS Support**: Secures communication with SSL certificates.\n-   **Automatic Redirection**: Redirects HTTP traffic to HTTPS.\n-   **Dockerized Setup**: Easy deployment with Docker Compose.\n\n---\n\n## Prerequisites\n\n-   **Docker** and **Docker Compose** installed on your system.\n-   Basic knowledge of Docker and Nginx configuration.\n\n---\n\n## Project Structure\n\n```\n└── 📁master-nginx\n    └── 📁certs\n        └── nginx-selfsigned.crt\n        └── nginx-selfsigned.key\n    └── 📁images\n        └── career-quiz.png\n        └── devops.png\n        └── devsecops.png\n        └── it-beginners.png\n    └── docker-compose.yaml\n    └── Dockerfile\n    └── index.html\n    └── nginx.conf\n    └── package-lock.json\n    └── package.json\n    └── README.md\n    └── server.js\n```\n\n## Setup Instructions\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/korngsamnang/master-nginx\ncd master-nginx\n```\n\n### 2. Generate SSL Certificates\n\nTo enable HTTPS, you need SSL certificates. Use the following openssl command to generate self-signed certificates:\n\n```bash\nopenssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx-selfsigned.key -out nginx-selfsigned.crt\n```\n\nExplanation:\n\n-   req: Initiates a certificate request.\n-   x509: Creates a self-signed certificate instead of a certificate signing request (CSR).\n-   nodes: Skips the option to encrypt the private key (no passphrase).\n-   days 365: Validity period of the certificate (1 year).\n-   newkey rsa:2048: Generates a new RSA key pair with 2048 bits.\n-   keyout: Specifies the filename for the private key.\n-   out: Specifies the filename for the certificate.\n\nPlace the generated nginx-selfsigned.crt and nginx-selfsigned.key files in the certs/ directory.\n\n### 3. Build and Run the Containers\n\nRun the following command to build and start the services:\n\n```bash\ndocker-compose up --build -d\n```\n\n### 4. Access the Application\n\n-   HTTPS: https://localhost\n-   HTTP requests will be automatically redirected to HTTPS.\n\n## Nginx Configuration\n\nThe nginx.conf file contains the following:\n\n-   Upstream Block: Defines the load-balancing strategy (least_conn) and targets the three Node.js services (app1, app2, app3).\n-   SSL Configuration: Uses self-signed certificates located in the certs/ directory.\n-   HTTP to HTTPS Redirect: Ensures secure connections by redirecting HTTP traffic.\n\n## Docker Compose Services\n\n-   app1, app2, app3:\n\n    -   Node.js applications running on the internal network.\n    -   Not exposed to the host but accessible via the Nginx proxy.\n\n-   nginx:\n\n    -   Acts as a reverse proxy and load balancer.\n    -   Listens on ports 80 (HTTP) and 443 (HTTPS).\n\n## Troubleshooting\n\n-   Check Logs: Use docker-compose logs to view logs for all services.\n-   Rebuild Containers: If changes are made, rebuild with docker-compose up --build.\n-   Certificate Errors: For development, bypass browser warnings for self-signed certificates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorngsamnang%2Fmaster-nginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkorngsamnang%2Fmaster-nginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorngsamnang%2Fmaster-nginx/lists"}