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;
}
评论区