(2) Consul集群统一网关访问(网关单点)

1. 只考虑三个Server(未使用consul client)

2. 启动网关

docker run --name consul_nginx -p 80:80 -v /home/nginx/nginx-single.conf:/etc/nginx/nginx.conf -d nginx:v1

配置文件nginx-single.conf:

worker_processes  1;

events {
  worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;

  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  access_log  logs/access.log  main;

  sendfile        on;

  keepalive_timeout  65;

  upstream consul_server {
     ip_hash;
     server 10.40.66.143:8500 weight=2 max_fails=3 fail_timeout=30s;
     server 10.40.66.145:8500 weight=2 max_fails=3 fail_timeout=30s;
     server 10.40.66.146:8500 weight=2 max_fails=3 fail_timeout=30s;
  }

  server {
    listen       80;
    server_name  localhost;
    location / {
        proxy_pass   http://consul_server;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   html;
    }
  }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章