diff --git a/.env.example b/.env.example index f8209f46d40bb5947e16d98f126b6f2a634ed246..4b6ec2500455d9d90dbdb2eb2da08f22c69b6e80 100644 --- a/.env.example +++ b/.env.example @@ -9,5 +9,8 @@ DB_NAME=film-db # ADMINER ADMINER_PORT=8080 +# NGINX +NGINX_PORT=3050 + # CLIENT CLIENT_PORT=3000 diff --git a/docker-compose.yml b/docker-compose.yml index a3c568507ecbf46ba016da700befbefada105898..d4073859049393946be92a1b6f4fca36b35dafd4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,6 +50,24 @@ services: depends_on: - postgres + nginx: + container_name: nginx + image: nginx:1.21.6-alpine + ports: + - 127.0.0.1:${NGINX_PORT}:${NGINX_PORT} + volumes: + - ./nginx/templates:/etc/nginx/templates + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + networks: + - backend-network + environment: + - NGINX_PORT=${NGINX_PORT} + - SERVER_PORT=${SERVER_PORT} + restart: always + depends_on: + - server + - postgres + client: container_name: client image: client:1.0.0 diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..e39c4ff5b869d5eb4278e325c3b90e6c1e78bb1e --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,28 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log; +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"'; + + # TODO: logging does not work + access_log /var/log/nginx/access.log; + + sendfile on; + + keepalive_timeout 65; + + # template files in /etc/nginx/templates/*.template are outputed as a result of executing envsubst to the /etc/nginx/conf.d folder + include /etc/nginx/conf.d/*.conf; +} diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template new file mode 100644 index 0000000000000000000000000000000000000000..1b0ec6a743d462d39dd84101796f65998c4017df --- /dev/null +++ b/nginx/templates/default.conf.template @@ -0,0 +1,27 @@ +upstream nest_server { + # TODO: must be same port as the nestJS server container port + server server:3000; +} + +server { + # IPv4 + listen ${NGINX_PORT} default_server; + # IPv6 + listen [::]:${NGINX_PORT} default_server; + + location / { + proxy_http_version 1.1; + proxy_cache_bypass $http_upgrade; + + #proxy_buffering off; + + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_pass http://nest_server; + } +}