diff --git a/config/include/location.conf b/config/include/location.conf new file mode 100644 index 0000000..e69de29 diff --git a/config/include/upstream.conf b/config/include/upstream.conf new file mode 100644 index 0000000..e69de29 diff --git a/config/nginx.conf b/config/nginx.conf index 9e25978..bd49d87 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -1,93 +1,86 @@ - - worker_processes auto; - -events { - worker_connections 1024; +upstream web { + server web:3000; } +upstream api { + server api:3001; +} -http { +upstream app { + server application:80; +} - upstream web { - server web:3000; + include /etc/nginx/include/upstream.conf; + + +server { + listen 80; + include /etc/nginx/mime.types; + + gzip on; + gzip_min_length 1000; + gzip_proxied any; + gzip_comp_level 1; + gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; + gzip_vary on; + gzip_disable "msie6"; + + + error_page 401 /login; + + + location = /auth { + internal; + + proxy_pass http://api; + + proxy_pass_request_body off; + proxy_set_header Content-Length ""; + proxy_set_header X-Original-URI $request_uri; + proxy_set_header X-Original-Remote-Addr $remote_addr; + proxy_set_header X-Original-Host $host; + proxy_intercept_errors on; } - upstream api { - server api:3001; + location ~ ^/(signin|logout|get-user) { + proxy_pass http://api; + + proxy_redirect off; + proxy_set_header X-Original-URI $request_uri; + proxy_set_header X-Original-Remote-Addr $remote_addr; + proxy_set_header X-Original-Host $host; } - upstream app { - server application:80; + location ~ ^/login { + proxy_pass http://web; + + 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; } - server { - listen 80; - include /etc/nginx/mime.types; + location / { + proxy_pass http://app; - gzip on; - gzip_min_length 1000; - gzip_proxied any; - gzip_comp_level 1; - gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; - gzip_vary on; - gzip_disable "msie6"; + 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; - - error_page 401 /login; - - - location = /auth { - internal; - - proxy_pass http://api; - - proxy_pass_request_body off; - proxy_set_header Content-Length ""; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Original-Remote-Addr $remote_addr; - proxy_set_header X-Original-Host $host; - proxy_intercept_errors on; - } - - location ~ ^/(signin|logout|get-user) { - proxy_pass http://api; - - proxy_redirect off; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Original-Remote-Addr $remote_addr; - proxy_set_header X-Original-Host $host; - } - - location ~ ^/login { - proxy_pass http://web; - - 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; - } - - - location / { - proxy_pass http://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; - - auth_request /auth; - auth_request_set $auth_cookie $upstream_http_set_cookie; - add_header Set-Cookie $auth_cookie; - } - - location = /health { - access_log off; - add_header 'Content-Type' 'application/json'; - return 200 'UP'; - } + auth_request /auth; + auth_request_set $auth_cookie $upstream_http_set_cookie; + add_header Set-Cookie $auth_cookie; } -} \ No newline at end of file + + location = /health { + access_log off; + add_header 'Content-Type' 'application/json'; + return 200 'UP'; + } + + include /etc/nginx/include/location.conf; +} diff --git a/docker-compose.yml b/docker-compose.yml index fc5109c..6c691e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,6 +42,7 @@ services: image: nginx:alpine volumes: - ./config/nginx.conf:/etc/nginx/templates/default.conf.template + - ./config/include:/etc/nginx/include restart: always depends_on: - web