标签:serve version info bcd pst 策略 依次 一段 max
对上游(比如tomcat)服务使用 keepalive 长连接
proxy_http_version 1.1; # 1.0 不支持长链接, 所以重置下, 为1.1 proxy_set_header Connection ""; upstream rrups { server 127.0.0.1:8011 weight=2 max_conns=2 max_fails=2 fail_timeout=5; server 127.0.0.1:8012; keepalive 32; } server { server_name rrups.liuhonghe.me; error_log myerror.log info; location /{ proxy_pass http://rrups; proxy_http_version 1.1; proxy_set_header Connection ""; } }
以ip为基础, 即使上游服务端挂了, 也会一直访问一台服务器
log_format varups ‘$upstream_addr $upstream_connect_time $upstream_header_time $upstream_response_time ‘ ‘$upstream_response_length $upstream_bytes_received ‘ ‘$upstream_status $upstream_http_server $upstream_cache_status‘; upstream iphashups { #ip_hash; # curl -H ‘X-Forwarded-for: 192.168.1.100 iphash.liuhonghe.me?username=abcdefg‘ hash user_$arg_username; # 使用特定字符串作为hash, 除非username更改, 否则不会更改 server 127.0.0.1:8011 weight=2 max_conns=2 max_fails=2 fail_timeout=5; # 使用ip_hash 后权重不生效 server 127.0.0.1:8012 weight=1; } server { set_real_ip_from 116.62.160.193; real_ip_recursive on; real_ip_header X-Forwarded-For; server_name iphash.liuhonghe.me; error_log myerror.log info; access_log logs/upstream_access.log varups; location /{ proxy_pass http://iphashups; proxy_http_version 1.1; proxy_set_header Connection ""; } }
以上所述就是小编给大家介绍的《nginx 核心知识100讲笔记(二)》,希望对大家有所帮助
标签:serve version info bcd pst 策略 依次 一段 max
原文地址:https://www.cnblogs.com/it-chen/p/11661413.html