refactor Nginx configuration for improved backend and frontend proxy handling

This commit is contained in:
2025-08-05 22:41:29 +03:00
parent c5a23b4671
commit af4d262a15
4 changed files with 60 additions and 32 deletions

2
back

Submodule back updated: 453930251b...812e30a2f8

View File

@ -1,38 +1,67 @@
upstream backned { proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
server unix:/app/run/socket.sock;
upstream backend
{
server unix:/app/run/socket0.sock;
server unix:/app/run/socket1.sock;
server unix:/app/run/socket2.sock;
server unix:/app/run/socket3.sock;
} }
upstream frontend { upstream frontend
{
server front:3000; server front:3000;
} }
server
{
listen 80; server_name crm.logidex.ru;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml application/json text/plain text/xml;
server { # Общие proxy_set_header, унаследованные всеми location
listen 80;
server_name crm.logidex.ru;
location /api {
proxy_pass http://backned;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
location /api
{
proxy_pass http://backend;
} }
location / { location /
{
proxy_pass http://frontend; proxy_pass http://frontend;
proxy_set_header Host $http_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;
} }
location /_next/webpack-hmr { location /_next/webpack-hmr
{
proxy_pass http://frontend; proxy_pass http://frontend;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; proxy_set_header Connection "upgrade";
proxy_set_header Host $host; }
location /_next/static
{
proxy_cache STATIC;
proxy_pass http://frontend;
add_header X-Cache-Status $upstream_cache_status;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}
location /static
{
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://frontend;
} }
} }

View File

@ -11,8 +11,6 @@ services:
restart: unless-stopped restart: unless-stopped
front: front:
image: git.logidex.ru/fakz9/crm-frontend:latest image: git.logidex.ru/fakz9/crm-frontend:latest
depends_on:
- back
env_file: env_file:
- config/front/.env - config/front/.env
networks: networks:
@ -25,6 +23,7 @@ services:
- "443:443" - "443:443"
depends_on: depends_on:
- back - back
- front
volumes: volumes:
- type: bind - type: bind
source: ./config/nginx/nginx.conf source: ./config/nginx/nginx.conf

2
front

Submodule front updated: cd034bcce6...1047a0b5fe