假设咱们在 192.168.137.11:8080 上有一个web服务,在 192.168.137.12 配置了一台 nginx,咱们能够进行以下配置:html
location / {
proxy_pass http://192.168.137.11:8080;
}nginx
这样配置后,咱们对 192.168.137.12 的访问都会被转发到 192.168.137.11:8080,此时这台 nginx 就是反向代理服务器。web
负载均衡:服务器
如今还有一台 192.168.137.13:8080 提供与 192.168.137.11:8080 同样的web 服务,nginx 经过下面的配置,能够实现负载均衡。负载均衡
upstream loadbalance {代理
ip_hash;
server 192.168.137.11:8080;
server 192.168.137.48:8080; server
#下面的3行配置是用于检查上面配置的服务器的状态的
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;htm
}ip
server {
listen 80;
server_name www.nginx1.com;hash
location / {
proxy_pass http://loadbalance;
root html;
index index.html index.htm;
}
location /status { #经过此URL(www.nginx1.com/status)可查看服务器的状态。这功能被 tengine 加强了
check_status;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}