企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### Proxy配置 需创建扩展配置目录 ```shell mkdir -p /usr/local/nginx/conf/extra ``` #### 主配置文件 nginx.conf ```shell user nginx nginx; # 设置所有worker进程可以打开的最大文件句柄数 worker_rlimit_nofile 65535; worker_processes auto; worker_cpu_affinity auto; events { # 让多个worker进程轮询相应新请求 accept_mutex on; # 限制每个worker进程的并发连接数 worker_connections 10240; use epoll; } http { include mime.types; default_type application/octet-stream; # 开启高效文件传输模式 sendfile on; tcp_nodelay on; tcp_nopush on; # 设置客户端连接保持会话的超时时间 keepalive_timeout 10; # 设置客户端请求头读取超时时间 client_header_timeout 15; # 设置客户端请求主体读取超时时间 client_body_timeout 15; # 指定响应客户端的超时时间 send_timeout 15; # 设置最大的容许的客户端请求主体大小 client_max_body_size 10M; # 将http请求响应头里的nginx版本号信息隐藏 server_tokens off; # 开启压缩 gzip on; # 设置容许压缩的页面最小字节数 gzip_min_length 1k; # 申请4个单位为32K的内存作为压缩结果流缓存 gzip_buffers 4 32k; # 压缩的版本 gzip_http_version 1.1; # 由于IE6对Gzip压缩效果不好,建议在IE6的环境下关闭压缩功能 gzip_disable "MSIE[1-6]"; # 压缩比率 gzip_comp_level 3; # 指定压缩的类型 gzip_types text/plain text/css text/xml application/javascript application/x-javascript; # 设置从web服务器传给缓存服务器的时候不被解压。只有传送到用户后才解压缩 gzip_vary on; # 设置为Json格式,方便ELK日志分析软件处理 log_format json_main '{"@timestamp":"$time_iso8601",' '"remote_addr":"$server_addr",' '"remote_user":"$remote_user",' '"request_time":"$request_time",' '"request":"$request",' '"body_bytes_sent":"$body_bytes_sent",' '"request_method":"$request_method",' '"upstream_response_time":"$upstream_response_time",' '"upstream_addr":"$upstream_addr",' '"url":"$uri",' '"http_x_forwarded_for":"$http_x_forwarded_for",' '"http_referrer":"$http_referer",' '"status":"$status"}'; access_log logs/access.log json_main; error_log logs/error.log error; includr extra/*.conf; upstream static_pool { server 192.168.254.204:8000 weight=5 max_fails=2 fail_timeout=3; server 192.168.254.205:8000 weight=5 max_fails=2 fail_timeout=3; } upstream dynamic_pool { server 192.168.254.206:8080 weight=5 max_fails=2 fail_timeout=3; server 192.168.254.207:8080 weight=5 max_fails=2 fail_timeout=3; least_conn; } } ``` #### 扩展配置 www.conf ```shell location / { proxy_pass http://static_pool/; } location ^~ /dynamic/ { proxy_pass http://dynamic_pool/; } # 设置防盗链(注意,跳转链接使用其他域名) location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass http://static_pool; valid_referers none blocked *.test.com; if ($invalid_referer) { rewrite ^/ http://www.unionsmart.cn/images/nolink.jpg; } } # 限制请求方法 if ($request_method !~ ^(GET|HEAD|POST)$ ) { return 444; } # 定义错误页面 error_page 400 403 404 405 408 410 411 412 413 414 415 http://www.noteshare.cn/www/40x.html; # 定义错误页面 error_page 500 502 503 504 http://www.noteshare.cn/www/50x.html; # 定义访问日志 access_log logs/proxy_access.log json_main; } ``` #### 扩展配置 proxy.conf ```shell # 当后端web服务器上也配置多个虚拟主机时,需要用该header来区分反向代理哪个主机名。 proxy_set_header Host $host; # 通过$remote_addr变量获取前端客户真实IP地址。 proxy_set_header X-Real-IP $remote_addr; # 通过$remote_addr变量获取前端客户真实IP地址。 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 设置缓冲区 proxy_buffering on; # 设置后端服务器的响应头大小,是响应头的缓冲区。 proxy_buffer_size 4k; # 设置缓冲区的数量和大小,nginx从代理的后端服务器获取的响应信息会放置到缓冲区。 proxy_buffers 8 32k; #此设置表示nginx会在没有完全读完后端响应的时候就开始向客户端传送数据,所以它会划出一部分缓冲区来专门向客户端传送数据。建议为proxy_buffers中单个缓冲区大小的2倍) proxy_busy_buffers_size 64K; # 指定当响应内容大于proxy_buffers指定的缓冲区时, 写入硬盘的临时文件的大小。 proxy_max_temp_file_size 1024m; # 一次访问能写入的临时文件的大小,默认是proxy_buffer_size和proxy_buffers中设置的缓冲区大小的2倍。 proxy_temp_file_write_size 128k; # proxy_request_buffering on; # proxy_ignore_headers Set-Cookie; # 表示与后端服务器连接的超时时间 proxy_connect_timeout 60s; # 表示后端服务器的数据回传时间 proxy_send_timeout 300; # 设置nginx从代理的后端服务器获取信息的时间 proxy_read_timeout 300s; ```