nginx动态配置配置

nginx中的conf文件配置测试

upstream backServer{
        server 127.0.0.1:11111;
        upsync 192.168.212.134:8500/v1/kv/upstreams/itmayiedu upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
        upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf;
    }

    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://backServer;

###nginx与上游服务器(真实访问的服务器)超时时间 后端服务器连接的超时时间_发起握手等候响应超时时间
			proxy_connect_timeout 1s;
			###nginx发送给上游服务器(真实访问的服务器)超时时间
            proxy_send_timeout 1s;
			### nginx接受上游服务器(真实访问的服务器)超时时间
            proxy_read_timeout 1s;
            index  index.html index.htm;
        }
    }

upsync指令指定从consul哪个路径拉取上游服务器配置;upsync_timeout配置从consul拉取上游服务器配置的超时时间;upsync_interval配置从consul拉取上游服务器配置的间隔时间;upsync_type指定使用consul配置服务器;strong_dependency配置nginx在启动时是否强制依赖配置服务器,如果配置为on,则拉取配置失败时nginx启动同样失败。upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。

注意:替换 consul 注册中心地址

创建upsync_dump_path

mkdir /usr/local/nginx/conf/servers/

upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。

启动consul

./consul agent -dev -ui -node=consul-dev -client=192.168.72.130

添加nginx  Upstream服务

1.使用linux命令方式发送put请求

curl -X PUT http://192.168.72.130:8500/v1/kv/upstreams/itmayiedu/192.168.72.1:8081

curl -X PUT http://192.168.72.130:8500/v1/kv/upstreams/itmayiedu/192.168.72.1:8083

负载均衡信息参数

{"weight":1, "max_fails":2, "fail_timeout":10, "down":0}

http://192.168.72.130:8500/

 

 

相关学习实战文档:https://drive.wps.cn/view/l/s9vrtkp

 

猜你喜欢

转载自blog.csdn.net/qq_32711309/article/details/85781120