config: add include custom upstream and location

This commit is contained in:
vchikalkin 2023-10-18 13:17:34 +03:00
parent 43126e3425
commit a683bc30cc
4 changed files with 73 additions and 79 deletions

View File

View File

View File

@ -1,93 +1,86 @@
upstream web {
worker_processes auto; server web:3000;
events {
worker_connections 1024;
} }
upstream api {
http { server api:3001;
}
upstream web {
server web:3000; upstream app {
} server application:80;
}
upstream api {
server api:3001; include /etc/nginx/include/upstream.conf;
}
upstream app { server {
server application:80; listen 80;
} include /etc/nginx/mime.types;
gzip on;
server { gzip_min_length 1000;
listen 80; gzip_proxied any;
include /etc/nginx/mime.types; 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 on; gzip_vary on;
gzip_min_length 1000; gzip_disable "msie6";
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; error_page 401 /login;
gzip_vary on;
gzip_disable "msie6";
location = /auth {
internal;
error_page 401 /login;
proxy_pass http://api;
location = /auth { proxy_pass_request_body off;
internal; proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_pass http://api; proxy_set_header X-Original-Remote-Addr $remote_addr;
proxy_set_header X-Original-Host $host;
proxy_pass_request_body off; proxy_intercept_errors on;
proxy_set_header Content-Length ""; }
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Original-Remote-Addr $remote_addr; location ~ ^/(signin|logout|get-user) {
proxy_set_header X-Original-Host $host; proxy_pass http://api;
proxy_intercept_errors on;
} proxy_redirect off;
proxy_set_header X-Original-URI $request_uri;
location ~ ^/(signin|logout|get-user) { proxy_set_header X-Original-Remote-Addr $remote_addr;
proxy_pass http://api; proxy_set_header X-Original-Host $host;
}
proxy_redirect off;
proxy_set_header X-Original-URI $request_uri; location ~ ^/login {
proxy_set_header X-Original-Remote-Addr $remote_addr; proxy_pass http://web;
proxy_set_header X-Original-Host $host;
} proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
location ~ ^/login { proxy_set_header Connection 'upgrade';
proxy_pass http://web; proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_http_version 1.1; }
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host; location / {
proxy_cache_bypass $http_upgrade; proxy_pass http://app;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
location / { proxy_set_header Connection 'upgrade';
proxy_pass http://app; proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; auth_request /auth;
proxy_set_header Connection 'upgrade'; auth_request_set $auth_cookie $upstream_http_set_cookie;
proxy_set_header Host $host; add_header Set-Cookie $auth_cookie;
proxy_cache_bypass $http_upgrade; }
auth_request /auth; location = /health {
auth_request_set $auth_cookie $upstream_http_set_cookie; access_log off;
add_header Set-Cookie $auth_cookie; add_header 'Content-Type' 'application/json';
} return 200 'UP';
}
location = /health {
access_log off; include /etc/nginx/include/location.conf;
add_header 'Content-Type' 'application/json';
return 200 'UP';
}
}
} }

View File

@ -42,6 +42,7 @@ services:
image: nginx:alpine image: nginx:alpine
volumes: volumes:
- ./config/nginx.conf:/etc/nginx/templates/default.conf.template - ./config/nginx.conf:/etc/nginx/templates/default.conf.template
- ./config/include:/etc/nginx/include
restart: always restart: always
depends_on: depends_on:
- web - web