Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx负载均衡(upstream)与反向代理(proxy_pass) #8

Open
hsipeng opened this issue Nov 24, 2017 · 0 comments
Open

nginx负载均衡(upstream)与反向代理(proxy_pass) #8

hsipeng opened this issue Nov 24, 2017 · 0 comments

Comments

@hsipeng
Copy link
Owner

hsipeng commented Nov 24, 2017

nginx 的负载均衡配置起来很简单, 如下:

    upstream resinserver{
        ip_hash;
        server 127.0.0.1:8000 down;
        server 127.0.0.1:8080 weight=2;
        server 127.0.0.1:6801;
        server 127.0.0.1:6802 backup;
    }

    #Ip_hash:每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题
    #down:不参与负载均衡
    #weight:比重,越大的分配的越多
    #backup:其他的非backup机器都down或者忙的时候才会请求到这台机器
```

例子:

```
一个简单的负载均衡与反向代理配合使用的例子

http{
  upstream test{
    ip_hash;
    server  127.0.0.1:8888
    server  127.0.0.1:9999
  }

  server {
    listen 80;
    server_name test.com

    location / {
      proxy_pass http://test;
      proxy_set_header Host $host:8888;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant