欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > nginx中stream和upstream

nginx中stream和upstream

2025/2/7 3:48:35 来源:https://blog.csdn.net/qq_25096749/article/details/145429984  浏览:    关键词:nginx中stream和upstream

七层负载均衡在http{}段里,根据用户的某些属性来做代理,比如location中以某个url结尾的页面或匹配某个主机头

http {#后端web地址池   upstream www_pool {server 172.16.1.7:80  weight=1;server 172.16.1.8:80  weight=1;server 172.16.1.9:81  weight=1;
}server {listen       80;#多个域名用空格隔开server_name  www.etiantian.org bbs.etiantian.org;   location / {index  index.html index.htm;#反向代理到地址池proxy_pass http://www_pool;proxy_set_header Host  $host;proxy_set_header X-Forwarded-For $remote_addr;}}
}# 访问www.etiantian.org的80端口就跳转到www_pool

四层负载均衡使用stream,stream模块配置在http{}模块外面
四层反向代理:基于ip+端口做代理

worker_processes auto;
error_log logs/error.stream.log info;
events {worker_connections  1024;
}http {}stream {# 这个日志会把客户端日志发送到后端upstream集群log_format  main  '$remote_addr [$time_local]''$protocol $status $bytes_sent $bytes_received ''$session_time "$upstream_addr" ''"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';access_log  /var/log/nginx/access.log  main;upstream backend {hash $remote_addr consistent;     # 采用ip_hash算法server 127.0.0.1:12346;server 127.0.0.1:12347;            max_fails=3 fail_timeout=30s;server 127.0.0.1:12348;            max_fails=3 fail_timeout=30s;}server {listen 80; # 由于nginx与master节点复用,这个监听端口不能是6443,否则会冲突proxy_pass backend;     #下面不支持X-FORWORD类型写法}
# 访问本机的ip+80端口就跳转到本机的12346-12348上去stream {log_format proxy '$remote_addr [$time_local]''$protocol $status $bytes_sent $bytes_received ''$session_time "$upstream_addr" ''"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';error_log  /var/log/nginx/udp-error.log    error;access_log /var/log/nginx/udp-access.log proxy ;server{preread_buffer_size 0;listen 30000-30150 udp reuseport;  # 这里最多只能写1000个端口listen 31000-31100 udp reuseport;listen 32000-32100 udp reuseport;proxy_pass 10.30.0.91:$server_port;#proxy_pass 10.30.0.90:30015;}
}
# 访问本机的ip+30000-32100端口就跳转到10.30.0.91:$server_port# 如果yum安装的nginx报错nginx: [emerg] unknown directive "stream",则安装如下模块
# yum install nginx-mod-stream -y
或源码包安装stream模块,这里连接里面有     
https://blog.csdn.net/qq_30614345/article/details/131322418# 如果启动nginx报错【Too many open files)】,就把udp启动的数量调小点。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com