{"id":25948822,"url":"https://github.com/sakaroncloud/docker-nginx-node-tls","last_synced_at":"2026-04-19T02:02:03.575Z","repository":{"id":279787490,"uuid":"939968017","full_name":"sakaroncloud/docker-nginx-node-tls","owner":"sakaroncloud","description":"This repository contains the complete configuration for a Node.js application with Docker and Nginx. The project sets up a scalable environment using Nginx as a reverse proxy.","archived":false,"fork":false,"pushed_at":"2025-02-27T13:51:21.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-14T17:23:15.840Z","etag":null,"topics":["certbot","docker","load-balancer","nginx","nodejs","tls"],"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/sakaroncloud.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-02-27T12:01:09.000Z","updated_at":"2025-05-06T07:43:32.000Z","dependencies_parsed_at":"2025-02-27T16:58:10.342Z","dependency_job_id":"8b060b87-a5fd-4552-a5cb-adf3cbe12b26","html_url":"https://github.com/sakaroncloud/docker-nginx-node-tls","commit_stats":null,"previous_names":["sakaroncloud/docker-nginx-node-tls"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sakaroncloud/docker-nginx-node-tls","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakaroncloud%2Fdocker-nginx-node-tls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakaroncloud%2Fdocker-nginx-node-tls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakaroncloud%2Fdocker-nginx-node-tls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakaroncloud%2Fdocker-nginx-node-tls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakaroncloud","download_url":"https://codeload.github.com/sakaroncloud/docker-nginx-node-tls/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakaroncloud%2Fdocker-nginx-node-tls/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31991720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["certbot","docker","load-balancer","nginx","nodejs","tls"],"created_at":"2025-03-04T11:23:21.989Z","updated_at":"2026-04-19T02:02:03.526Z","avatar_url":"https://github.com/sakaroncloud.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nginx Docker Node.js App with Load Balancer and Domain Configuration\n\nThis project provides a complete setup for a Node.js application using Docker and Nginx. It incorporates a load balancer for distributing traffic across multiple containers, ensuring high availability and scalability. The application is also configured to use a custom domain name.\n\n## Features\n\n- **Dockerized Node.js Application:** Easily deploy your Node.js application in Docker containers.\n- **Nginx Reverse Proxy:** Routes incoming traffic to the appropriate containers.\n- **Load Balancing:** Efficiently distributes requests between multiple Node.js containers.\n- **Custom Domain Integration:** Configured to use a custom domain for better accessibility and ssl encryption.\n- **Scalable Architecture:** Add more Node.js containers to handle higher traffic loads.\n\n## Technologies\n\n- **Node.js** – The backend application framework.\n- **Docker** – Containerizes the Node.js application.\n- **Nginx** – Configured as a reverse proxy and load balancer.\n- **Load Balancing** – Ensures even distribution of traffic across Node.js instances.\n- **Custom Domain** – Configured for easier access and enhanced security.\n- **TLS Configuration** – For SSL certificate.\n\n## Requirements\n\n- Docker \u0026 Docker Compose installed on your local machine or server.\n- A valid domain name (if you want to configure custom domain access).\n- A server (for hosting Docker containers and Nginx).\n\n## Getting Started\n\nFollow the steps below to set up the project locally or on a server.\n\n### Clone the repository\n\nClone this repository to your local machine or server:\n\n```bash\ngit clone https://github.com/sakaroncloud/docker-nginx-node-tls.git\ncd docker-nginx-node-tls\n```\n\n### Bind Mounts\nIn docker compose, you have to map configuration files in local directory with the container directory. It depends on operating system and also with your project directory. \n```bash\nFor Windows:\n❌ F:\\docker-nginx-node-tls\\nginx\\config:/etc/nginx/conf.d\n✅ /f/docker-nginx-node-tls/nginx/config:/etc/nginx/conf.d\n\nFor Linux/macOS:\n✅ /home/docker-nginx-node-tls/nginx/config:/etc/nginx/conf.d\n\nor use relative path\n✅ /nginx/config:/etc/nginx/conf.d\n\nNote: You can skip certbot volumes and services for local environment\n```\n\n### Build NodeApp\n```bash\ncd nodeapp\ndocker build -t nodeapp:v1 .\n```\n\n🎉 Congratulations! 🎉\n\nYou've successfully set up your Nginx configuration for local environment.  \n\n \n### 🔓 Configure Nginx For Local Deployment\nYou need to replace .com with .local in local environment.  \n❌ example.com  \n✅ example.local  \n❌ subdomain.example.com  \n✅ subdomain.example.local  \n\n```\n    # example.local.conf - for simple html or SPA like ReactJs\n    server {\n        listen 80;\n        listen [::]:80;\n        server_name example.local;\n        server_tokens off;\n\n        root /usr/share/nginx/html;\n        location / {\n            try_files $uri $uri/ /index.html;\n        }\n    }\n    \n```\n```\n    # subdomain.example.local - for nodeapp\n    upstream backend {\n        server node1:8000 weight=3;\n        server node2:8000 weight=1;\n    }\n\n    server {\n        listen 80;\n        listen [::]:80;\n        server_tokens off;\n        server_name subdomain.example.local;\n\n        location / {\n            # Proxy pass must point to upstream name\n            proxy_pass http://backend;\n\n            # Ensure HTTP/1.1 is used for persistent connections\n            proxy_http_version 1.1;\n\n            # Pass the original Host header to the backend\n            proxy_set_header Host $host;\n\n            # Forward real client IP instead of Nginx's IP (important for logging \u0026 auth)\n            proxy_set_header X-Real-IP $remote_addr;\n\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n            # Prevent response caching for dynamic content\n\n            proxy_cache_bypass $http_upgrade;\n            proxy_no_cache 1;\n            proxy_buffers 16 16k;\n            proxy_buffer_size 32k;\n        }\n\n    }\n```\n#### Configure Host Name in your system\n```bash\nFor Windows: C:\\Windows\\System32\\drivers\\etc\\hosts  \nFor Linux: /etc/hosts\n```\n\n```bash\nAdd the following lines to end of hosts file\n# NginxJs Tutorial\n127.0.0.1 example.local\n127.0.0.1 subdomain.example.local\n```\n#### Run docker compose\n\n```bash\ndocker compose up -d --build\nor\ndocker compose -f docker-compose.yml up -d --build\n```\n\n### 🔒 Configure Nginx For Production with SSL\n- Step 1 - Rename sample file name correcponding to your domain.  \n- Step 2 - Copy the below configuration for Nginx.  \n```\n# example.com.conf - for simple html or SPA like ReactJs\nserver {\n    listen 80;\n    listen [::]:80;\n    server_name example.com www.example.com;\n    server_tokens off;\n\n    root /usr/share/nginx/html;\n    \n    location /.well-known/acme-challenge/ {\n        root /var/www/certbot;\n    }\n\n    location / {\n        return 301 https://$host$request_uri;\n    }\n}\n\n```\n\n```\n# subdomain.example.com.conf - for nodeapp\nupstream backend {\n    server node1:8000 weight=3;\n    server node2:8000 weight=1;\n}\n\nserver {\n    listen 80;\n    listen [::]:80;\n    server_tokens off;\n    server_name subdomain.example.com;\n\n    location /.well-known/acme-challenge/ {\n        root /var/www/certbot;\n    }\n\n    location / {\n        return 301 https://$host$request_uri;\n    }\n\n}\n\n```\n- Step 3 - Run docker compose before adding SSL configuration in Nginx. By doing so, nginx will not fail to launch and certbot will also be able to ping acme-challenge and generate the certificate.\n```bash\ndocker compose up -d --build\nor\ndocker compose -f docker-compose.yml up -d --build\n```\n\n- Step 4 - Now also add SSL configuration to existing Nginx config\n\n```\n# example.com.conf - for simple html or SPA like ReactJs\nserver {\n    listen 443 ssl;\n    listen [::]:443 ssl;\n    server_name example.com www.example.com;\n    root /usr/share/nginx/html;\n    index index.html index.htm;\n    # SSL certificates\n    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;\n    location / {\n        try_files $uri $uri/ /index.html;\n    }\n     location /.well-known/acme-challenge/ {\n        root /var/www/certbot;\n    }\n}\n```  \n\n```\n# subdomain.example.com.conf - for nodeapp\nserver {\n    listen 443 ssl;\n    listen [::]:443 ssl;\n\n    server_name subdomain.example.com;\n   # SSL certificates\n    ssl_certificate /etc/letsencrypt/live/subdomain.example.com/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/subdomain.example.com/privkey.pem;\n    location / {\n        # Proxy pass must point to upstream name\n        proxy_pass http://backend;\n\n        # Ensure HTTP/1.1 is used for persistent connections\n        proxy_http_version 1.1;\n\n        # Pass the original Host header to the backend\n        proxy_set_header Host $host;\n\n        # Forward real client IP instead of Nginx's IP (important for logging \u0026 auth)\n        proxy_set_header X-Real-IP $remote_addr;\n\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        # Prevent response caching for dynamic content\n\n        proxy_cache_bypass $http_upgrade;\n        proxy_no_cache 1;\n        proxy_buffers 16 16k;\n        proxy_buffer_size 32k;\n    }\n     location /.well-known/acme-challenge/ {\n        root /var/www/certbot;\n    }\n}\n\n```  \n\n- Step 4 - Finally, SSL certificate is loaded into your Nginx configuration, you can restart nginx\n\n```bash\n# Login to Nginx Container\ndocker exec -it nginx sh\n\n# To test configuration\nnginx -t\n\n# To reload\nnginx -s reload\n```\n### Final Steps\n We can edit cronjob configuration file and add the following First open the file using  \n ```bash\n # Open cronjob file\n cronjob -e \n ```\n\n```bash\n# Add the configuration to the end of the file\n0 5 1 */2 *  docker compose -f /home/ubuntu/site/docker-compose.yml up certbot\n1 5 1 */2 *  docker exec nginx nginx -s reload\n```\n🎉 Congratulations! 🎉\n\nYou've successfully set up your Nginx configuration with proper SSL.\nKeep up the great work! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakaroncloud%2Fdocker-nginx-node-tls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakaroncloud%2Fdocker-nginx-node-tls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakaroncloud%2Fdocker-nginx-node-tls/lists"}