From 8b5fea6b2ce04d17c45b1e9ebee1a22d0c9dd4fe Mon Sep 17 00:00:00 2001 From: AmirRezaZahedi Date: Fri, 24 Oct 2025 23:59:01 +0330 Subject: [PATCH 1/2] update docker and nginx config --- backend/Dockerfile | 16 +++++++++++- docker-compose.yml | 46 +++++++++++++++++++++++++++++++- nginx/nginx.conf | 65 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 3feaa5b..775f466 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1 +1,15 @@ -# ADD DOCKERFILE CONTENTS HERE \ No newline at end of file +FROM node:18-alpine + +WORKDIR /app + + +COPY package*.json ./ +RUN npm install + + +COPY . . + + +EXPOSE 8080 + +CMD ["node", "src/index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index db39ad0..b5b5dc5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1 +1,45 @@ -# ADD DOCKER-COMPOSE CONTENT HERE \ No newline at end of file +version: '3.9' + +services: + nodeapp: + build: ./backend + container_name: nodeapp + ports: + - "3000:8080" + environment: + - REDIS_HOST=redis + - REDIS_PORT=6379 + - MONGODB_URI=mongodb://mongo:27017/mydb + - NODE_ENV=development + depends_on: + - redis + - mongo + + redis: + image: redis:7 + container_name: redis + ports: + - "6379:6379" + volumes: + - redis-data:/data + restart: unless-stopped + + mongo: + image: mongo:7 + container_name: mongo + ports: + - "27017:27017" + environment: + MONGO_INITDB_DATABASE: mydb + + nginx: + image: nginx:latest + container_name: nginx + ports: + - "1234:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + + +volumes: + redis-data: diff --git a/nginx/nginx.conf b/nginx/nginx.conf index e4efe51..c7e8b0a 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1 +1,64 @@ -# ADD NGINX CONFIGS HERE \ No newline at end of file +# nginx.conf +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + keepalive_timeout 65; + server_tokens off; + + upstream node_app { + server nodeapp:3000; + } + + server { + listen 80; + server_name localhost; + + # Health check endpoint + location /health { + proxy_pass http://node_app/health; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + # API routes + location /api/ { + proxy_pass http://node_app$request_uri; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + # Default fallback + location / { + proxy_pass http://node_app; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +} From 9bec5334c408fe7e89ae56c2a9d5dd295ed34f10 Mon Sep 17 00:00:00 2001 From: Amir Reza Zahedinejad <107708380+AmirRezaZahedi@users.noreply.github.com> Date: Sat, 25 Oct 2025 00:00:16 +0330 Subject: [PATCH 2/2] Update docker-compose.yml --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b5b5dc5..e3d27ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,8 +29,6 @@ services: container_name: mongo ports: - "27017:27017" - environment: - MONGO_INITDB_DATABASE: mydb nginx: image: nginx:latest @@ -43,3 +41,4 @@ services: volumes: redis-data: +