diff --git a/docker-compose.yml b/docker-compose.yml index a29c46c..a4fb7ee 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,10 +4,11 @@ services: nginx: container_name: nginx image: nginx + build: + dockerfile: Dockerfile + context: ./nginx ports: - 80:80 - volumes: - - ./nginx/conf.d:/etc/nginx/conf.d depends_on: - backend networks: diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..0c9d9f7 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx +EXPOSE 80 +RUN rm /etc/nginx/nginx.conf +COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/nginx/conf.d/app.conf b/nginx/conf.d/app.conf deleted file mode 100644 index d21e6f6..0000000 --- a/nginx/conf.d/app.conf +++ /dev/null @@ -1,12 +0,0 @@ -server { - listen 80; - access_log off; - - location / { - proxy_pass http://backend:8080; # docker-compose에서 설정한 이름이 backend - proxy_set_header Host $host:$server_port; - proxy_set_header X-Forwarded-Host $server_name; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } -} \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..c92866f --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,56 @@ +user nginx; +worker_processes 1; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; # 각 워커 프로세스가 동시에 처리할 수 있는 연결 수를 1024로 제한 +} + +http { + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server_tokens off; # 헤더에 NGINX 버전을 숨김 + keepalive_timeout 30s; # Nginx 웹 서버에서 클라이언트와의 연결을 유지하는 시간을 정의 + + log_format main '$remote_addr - $remote_user [$time_local] $status ' + '"$request" $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + upstream api { + server backend:8080; # docker-compose에서 설정한 이름이 backend + } + + upstream client { + server frontend:3000; # docker-compose에서 설정한 이름이 frontend + } + + server { + + listen 80; + access_log off; + + location / { + proxy_pass http://client; + } + + location /api { + + proxy_http_version 1.1; + proxy_pass http://api; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + } + +# location /api/v1 { #소셜 로그인 요청 API 추가 작성 (소셜 로그인 설정하실 때 필요하시면 쓰세요) +# +# +# } + } +} +