Nginx进阶篇之端口转发
nginx透传udp、tcp端口
-
需要nginx编译时,支持加载stream模块。
./configure --prefix=/usr/local/nginx --with-stream
-
配置stream 需要在nginx的http和events区域块之间配置即可。
user root; worker_processes auto; error_log logs/error.log; pid sbin/nginx.pid; events { use epoll; worker_connections 65535; } stream { upstream sipserver { server 192.168.127.2:5060 max_fails=1 fail_timeout=10s; server 192.168.127.3:5060 max_fails=1 fail_timeout=10s backup; } upstream httpapi { server 192.168.127.4:8080 max_fails=1 fail_timeout=10s; server 192.168.127.5:8080 max_fails=1 fail_timeout=10s backup; } server { listen 5060 udp reuseport; proxy_pass sipserver; } server { listen 18080; proxy_pass httpapi; } } http { include mime.types; default_type application/octet-stream; types { application/pdf; } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; fastcgi_buffers 8 128k; proxy_connect_timeout 1000; proxy_send_timeout 1000; proxy_read_timeout 1000; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; client_max_body_size 200m; server_tokens off; #add_header Set-Cookie "HttpOnly"; #add_header Set-Cookie "Secure"; #add_header X-Frame-Options SAMEORIGIN; include vhosts/local_upstream.conf; include vhosts/server.conf; proxy_buffering on; proxy_buffer_size 256k; proxy_buffers 64 256K; proxy_busy_buffers_size 512k; proxy_temp_file_write_size 512k; proxy_temp_path /tmp/temp_buffer; ######## # 开启压缩机制 gzip on; # 指定会被压缩的文件类型(也可自己配置其他类型) gzip_types text/plain application/javascript text/css application/xml text/javascript image/jpeg image/gif image/png; # 设置压缩级别,越高资源消耗越大,但压缩效果越好 gzip_comp_level 5; # 在头部中添加Vary: Accept-Encoding(建议开启) gzip_vary on; # 处理压缩请求的缓冲区数量和大小 gzip_buffers 16 8k; # 对于不支持压缩功能的客户端请求不开启压缩机制 gzip_disable "MSIE [1-6]\."; # 低版本的IE浏览器不支持压缩 # 设置压缩响应所支持的HTTP最低版本 gzip_http_version 1.1; # 设置触发压缩的最小阈值 gzip_min_length 10k; # 关闭对后端服务器的响应结果进行压缩 gzip_proxied off; }
本文由mdnice多平台发布
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具