持续更新,个人使用
#user nobody;
#进程数
worker_processes 1;
#错误日志配置
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#连接数配置
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#负载均衡配置
location /proxy {
proxy_pass http://backend
}
#上游服务器配置
upstream backend {
#负载均衡算法配置:
#round-robin(轮询,默认)
#ip_hash(根据 IP 哈希)
#hash key [consistent](根据指定的 key 哈希,可选一致性哈希)
round-robin;
#权重: weight
server 10.20.30.1:8080 weight=1
#失败重试: fail_timeout 时间内失败了 max_fails 次数,将摘掉上游服务器,fail_timeout 过后再次加入到存活服务器列表进行尝试
server 10.20.30.2:8080 max_fails=2 fail_timeout=10s weight=2
}
}
}