2 Star 5 Fork 2

cn-openjava/opencode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nginx.conf 4.23 KB
一键复制 编辑 原始数据 按行查看 历史
天空之城 提交于 2026-01-14 16:08 +08:00 . 支持流式输出
env PROXY_TARGET;
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10240M;
#使其不显示版本号
server_tokens off;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#开启压缩模式
gzip on;
gzip_static on;
gzip_min_length 1k;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_comp_level 4;
gzip_types text/plain application/javascript application/x-javascript text/css text/javascript application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
# 定义信任的代理IP段 - 增强版
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Real-IP;
real_ip_recursive on;
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
# 关键:正确设置转发头部
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;
# 针对Docker环境的额外头部
proxy_set_header X-Original-Remote-Addr $remote_addr;
# 新增:确保不覆盖现有头部
proxy_pass_header X-Forwarded-For;
}
location /rest {
resolver 127.0.0.11 valid=30s; # Docker默认DNS服务器
set_by_lua $proxy_target 'return os.getenv("PROXY_TARGET")';
proxy_pass $proxy_target;
rewrite ^/rest/(.*)$ /$1 break;
#proxy_set_header Host $host:$server_port;
# 关键:正确设置转发头部
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;
# 针对Docker环境的额外头部
proxy_set_header X-Original-Remote-Addr $remote_addr;
# 流式输出关键配置 - 支持Server-Sent Events (SSE)和流式响应
proxy_buffering off; # 禁用代理缓冲,允许实时流式传输
proxy_cache off; # 禁用缓存
proxy_read_timeout 300s; # 增加读取超时时间(5分钟)
proxy_send_timeout 300s; # 增加发送超时时间(5分钟)
proxy_http_version 1.1; # 使用HTTP/1.1以支持分块传输
chunked_transfer_encoding on; # 启用分块传输编码
# 设置响应头,禁用nginx内部缓冲
add_header X-Accel-Buffering no;
# 新增:确保不覆盖现有头部
proxy_pass_header X-Forwarded-For;
}
# 新增诊断接口
location /ip-debug {
add_header Content-Type text/plain;
return 200 "remote_addr: $remote_addr
\n
http_x_forwarded_for: $http_x_forwarded_for
\n
http_x_real_ip: $http_x_real_ip
\n
proxy_add_x_forwarded_for: $proxy_add_x_forwarded_for
\n
http_referer: $http_referer
\n
http_user_agent: $http_user_agent
\n
http_x_forwarded_for: $http_x_forwarded_for
\n
http_x_real_ip: $http_x_real_ip
\n
http_x_forwarded_proto: $http_x_forwarded_proto
\n
http_x_original_remote_addr: $http_x_original_remote_addr
\n
http_host: $http_host
\n
http_port: $http_port
\n
http_scheme: $http_scheme
\n
http_request_uri: $http_request_uri
\n
http_request_method: $http_request_method
\n
http_request_body: $http_request_body
\n
http_request_body_file: $http_request_body_file
\n";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cn-openjava/opencode.git
git@gitee.com:cn-openjava/opencode.git
cn-openjava
opencode
opencode
main

搜索帮助