http { default_type application/octet-stream; sendfile on; upstream swoft_server { server 172.22.22.110:18306 max_fails=2 fail_timeout=30s; upsync 172.22.22.30:8500/v1/kv/upstream/swoft_server upsync_timeout=1ms upsync_interval=1ms upsync_type=consul strong_dependency=on; # 这是容器中的目录 upsync_dump_path /Nginx/conf/swoft_server.conf; include /Nginx/conf/swoft_server.conf; } server { listen 80; server_name localhost; root /www; location / { proxy_pass http://swoft_server; } } } 解释: 172.22.22.30:8500/v1/kv/upstreams =》 连接consul的api资源地址 swoole_test =》 相当于我们自己在consul中自定义的key upsync_timeout =》 超时时间6分钟 upsync_interval =》 定时获取信息的时间 upsync_type =》 类型 strong_dependency=on; =》 是否依赖consul运行 upsync_dump_path =》 拉取之后申请配置文件
Nginx upsync 动态获取consul中的服务信息 strong_dependency是否依赖consul,获取服务信息后会生成一个配置文件。
搭建过程
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。