背景
Nginx代理的后端服務(wù)有2個實例墓臭,地址:
10.10.10.10:8080
10.10.10.20:8080
安裝
參見 http://www.reibang.com/p/affac5f2d56e
七層反向代理
- 配置
nginx.conf
嘿般,在http塊中添加
http {
......
include conf.d/*.conf;
}
- 編寫
conf.d/your.site.com.conf
upstream backend7 {
server 10.10.10.10:8080 max_fails=3 fail_timeout=3s;
server 10.10.10.20:8080 max_fails=3 fail_timeout=3s;
}
server {
listen 80;
server_name your.site.com;
access_log /var/log/nginx/access-your.site.com.log main;
location / {
proxy_pass http://backend7;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
}
四層反向代理
- 配置
nginx.conf
你弦,在stream塊中添加
stream {
......
include conf.d/*.stream;
}
- 編寫
conf.d/your.site.com.stream
upstream backend4 {
server 10.10.10.10:8080 max_fails=3 fail_timeout=3s;
server 10.10.10.20:8080 max_fails=3 fail_timeout=3s;
}
server {
listen 80;
proxy_pass backend4;
}
生效
-
檢測配置
# nginx -t
-
重啟
# /etc/init.d/nginx restart