nginx基本配置使用及负载均衡的四种方式
location / { proxy_pass http://127.0.0.1:1234; }
location / { #首页 index.html index.htm; //静态资源地址 root html; }
#自定义服务名 upstream tomcat_server{ server 127.0.0.1:1234; server 127.0.0.1:8769 backup;#热备 } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat_server; proxy_set_header Host $host; #配置端口,否则可能访问失败 }
#自定义服务名 upstream tomcat_server{ server 127.0.0.1:1234; server 127.0.0.1:8769; } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat_server; proxy_set_header Host $host; #配置端口,否则可能访问失败 }
#自定义服务名 upstream tomcat_server{ server 127.0.0.1:1234 weight=1; server 127.0.0.1:8769 weight=2; } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat_server; proxy_set_header Host $host; #配置端口,否则可能访问失败 }
#自定义服务名 upstream tomcat_server{ ip_hash; server 127.0.0.1:1234; server 127.0.0.1:8769; } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat_server; proxy_set_header Host $host; #配置端口,否则可能访问失败 }
upstream tomcat_server{ server 127.0.0.1:1234 weight=2 max_fails=2 fail_timeout=2; server 127.0.0.1:8769 weight=1 max_fails=2 fail_timeout=1; }