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\nhttp_x_forwarded_for: $http_x_forwarded_for\nhttp_x_real_ip: $http_x_real_ip\nproxy_add_x_forwarded_for: $proxy_add_x_forwarded_for\nhttp_referer: $http_referer\nhttp_user_agent: $http_user_agent\nhttp_x_forwarded_for: $http_x_forwarded_for\nhttp_x_real_ip: $http_x_real_ip\nhttp_x_forwarded_proto: $http_x_forwarded_proto\nhttp_x_original_remote_addr: $http_x_original_remote_addr\nhttp_host: $http_host\nhttp_port: $http_port\nhttp_scheme: $http_scheme\nhttp_request_uri: $http_request_uri\nhttp_request_method: $http_request_method\nhttp_request_body: $http_request_body\nhttp_request_body_file: $http_request_body_file\n";}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。