162 lines
4.1 KiB
Plaintext
162 lines
4.1 KiB
Plaintext
# Nginx多客户端反向代理配置
|
|
# 为3个不同地区客户端提供独立端口访问
|
|
# 所有请求最终转发到主服务 10.79.97.17:51703
|
|
|
|
# 上游服务器配置
|
|
upstream docreview_main {
|
|
server 10.79.97.17:51703;
|
|
keepalive 32;
|
|
}
|
|
|
|
# 客户端A - 端口51701
|
|
server {
|
|
listen 51701;
|
|
server_name 10.79.97.17;
|
|
|
|
# 访问日志
|
|
access_log /var/log/nginx/client-a-access.log;
|
|
error_log /var/log/nginx/client-a-error.log;
|
|
|
|
# 客户端标识
|
|
set $client_id "client-a";
|
|
|
|
location / {
|
|
# 反向代理到主服务
|
|
proxy_pass http://docreview_main;
|
|
|
|
# 设置代理头部
|
|
proxy_set_header Host $host:51703;
|
|
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_set_header X-Client-ID $client_id;
|
|
|
|
# 连接设置
|
|
proxy_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
|
|
# WebSocket支持
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 健康检查
|
|
location /health {
|
|
access_log off;
|
|
return 200 "Client A - OK";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|
|
|
|
# 客户端B - 端口51702
|
|
server {
|
|
listen 51702;
|
|
server_name 10.79.97.17;
|
|
|
|
# 访问日志
|
|
access_log /var/log/nginx/client-b-access.log;
|
|
error_log /var/log/nginx/client-b-error.log;
|
|
|
|
# 客户端标识
|
|
set $client_id "client-b";
|
|
|
|
location / {
|
|
# 反向代理到主服务
|
|
proxy_pass http://docreview_main;
|
|
|
|
# 设置代理头部
|
|
proxy_set_header Host $host:51703;
|
|
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_set_header X-Client-ID $client_id;
|
|
|
|
# 连接设置
|
|
proxy_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
|
|
# WebSocket支持
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 健康检查
|
|
location /health {
|
|
access_log off;
|
|
return 200 "Client B - OK";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|
|
|
|
# 客户端C - 端口51704
|
|
server {
|
|
listen 51704;
|
|
server_name 10.79.97.17;
|
|
|
|
# 访问日志
|
|
access_log /var/log/nginx/client-c-access.log;
|
|
error_log /var/log/nginx/client-c-error.log;
|
|
|
|
# 客户端标识
|
|
set $client_id "client-c";
|
|
|
|
location / {
|
|
# 反向代理到主服务
|
|
proxy_pass http://docreview_main;
|
|
|
|
# 设置代理头部
|
|
proxy_set_header Host $host:51703;
|
|
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_set_header X-Client-ID $client_id;
|
|
|
|
# 连接设置
|
|
proxy_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
|
|
# WebSocket支持
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 健康检查
|
|
location /health {
|
|
access_log off;
|
|
return 200 "Client C - OK";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
}
|
|
|
|
# 全局配置
|
|
# 错误页面
|
|
error_page 502 503 504 /50x.html;
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
}
|
|
|
|
# 安全头部
|
|
add_header X-Frame-Options DENY;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-XSS-Protection "1; mode=block"; |