网站首页 > 技术教程 正文
背景
当前在SpringCloud微服务架构下,网关作为服务的入口尤为重要,一旦网关发生单点故障会导致整个服务集群瘫痪,为了保证网关的高可用可以通过Nginx的反向代理功能实现网关的高可用。
项目架构图
- Nginx作为反向代理服务器,代理后端网关服务,通过Nginx自带的负载均衡算法进行转发
- Zull网关部署集群时,如果一台服务器发生故障,就会转发到另外一台机器上,服务正常访问,保证网关的高可用
具体部署
修改本地Host文件
(C:\Windows\System32\drivers\etc)编辑下面这个文件,修改里面ip对应的地址,因为要使用域名的不同来实现反向代理.
Nginx配置
下载
Nginx下载地址(Windows和Linux的配置一样): http://nginx.org/en/download.html
配置
解压后,找到配置文件\nginx-1.12.2\conf\nginx.conf
详细配置
#user nobody; worker_processes 1; #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; #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 0; keepalive_timeout 65; #gzip on; #配置上游服务器网关端口集群 upstream backServer{ # weight 权重:谁的的权重多,访问到哪个服务的几率就大 server 127.0.0.1:8040 weight=1; server 127.0.0.1:8041 weight=1; } server { # 注意:如果使用域名进行反向代理的话,Nginx的端口必须是80 listen 80; # 入口地址-对应域名地址 server_name www.taowd123.com; location /ms { ### 指定上游服务器负载均衡服务器 proxy_pass http://backServer/; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # 错误页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
测试
- 启动注册中心服务: http://127.0.0.1:8761/
- 启动两个网关,端口分别为:8041,8040
- 启动服务提供者,端口为:9000 已经在Zuul中配置
- 启动Nginx服务
- 访问注册中心检查服务
- 使用网关端口直接访问正常
- 使用host中配置的域名直接访问,测试反向代理功能
- 访问多次,检查网关后台输出结果
end:如果你觉得本文对你有帮助的话,记得关注点赞转发,你的支持就是我更新动力。
猜你喜欢
- 2024-10-11 KUBERNETES的六种端口(kubernetes hostport)
- 2024-10-11 漫画:Apache Nginx80 端口争夺战(apache服务器的默认端口是)
- 2024-10-11 Nginx处理redirect 端口丢失的问题
- 2024-10-11 Knative Service 是如何指定端口和协议的
- 2024-10-11 kubernetes nginx ingress 部署开放不同端口应用
- 2024-09-21 kubectl常用命令(二)(kubectl 命令)
- 2024-09-21 Nginx服务器-抓包分析反向代理跳转地址
- 2024-09-21 将kafka集群端口映射到公网访问(kafka集群使用)
- 2024-09-21 Linux查看被占用的端口(linux 查看端口占用被哪个进程占用)
- 2024-09-21 nginx怎么配置默认端口(nginx怎么配置默认端口命令)
你 发表评论:
欢迎- 最近发表
-
- Linux新手必看:几种方法帮你查看CPU核心数量
- linux基础命令之lscpu命令(linux中ls命令的用法)
- Linux lscpu 命令使用详解(linux常用ls命令)
- 如何查询 Linux 中 CPU 的数量?这几个命令要知道!
- 在linux上怎么查看cpu信息(linux如何查看cpu信息)
- 查看 CPU 的命令和磁盘 IO 的命令
- 如何在CentOS7上改变网卡名(centos怎么改网卡名字)
- 网工必备Linux网络管理命令(网工必备linux网络管理命令是什么)
- Linux 网络命令知多少(linux 网络 命令)
- Linux通过命令行连接wifi的方式(linux命令行连接无线网)
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)