nginx 负载均衡配置
来源:互联网 发布:桌面手机支架 知乎 编辑:程序博客网 时间:2024/06/06 18:52
要保持session的话使用ip_hash
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=static:10m inactive=30d max_size=1g;upstream tomcat {# ip_hash ; #hash $remote_addr consistent; server 127.0.0.1:8082 max_fails=1 fail_timeout=2s ; server 127.0.0.1:8083 max_fails=1 fail_timeout=2s ; server 127.0.0.1:8084 max_fails=1 fail_timeout=2s ; server 127.0.0.1:8081 max_fails=1 fail_timeout=2s ; keepalive 16;}upstream tomcat-web { ip_hash ; server 127.0.0.1:8081 max_fails=1 fail_timeout=2s; keepalive 16;}upstream tomcat-web-ua { ip_hash ; server 127.0.0.1:8081 max_fails=1 fail_timeout=2s; server 127.0.0.1:8082 max_fails=1 fail_timeout=2s; keepalive 16;}server { listen 80; listen [::]:80; server_name bkt.jeagine.com; charset utf-8; access_log /var/log/nginx/tomcat.access.log main; root xxxx; index index.html index.htm index.jsp; location ~ xxxx { if ($http_user_agent ~ "(Windows NT)" ) { proxy_pass http://www.baidu.com; break; return 403; } proxy_pass http://tomcat-web; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location ~ xxxx { proxy_pass http://tomcat-web; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location ~ xxxxx { proxy_pass http://tomcat-web; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location /api { proxy_pass http://tomcat/api; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location ^~ xxxxx { proxy_pass http://tomcat-web-ua; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location ~* ^.+.(js|css|ico|gif|jpg|jpeg|png|svg|xls)$ { proxy_pass http://tomcat ; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_cache static; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 302 7d; proxy_cache_valid 404 1m; proxy_cache_valid any 1h; add_header X-Cache $upstream_cache_status; #log_not_found off; #access_log off; expires max; } location / { proxy_pass http://tomcat-web-ua; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 65; proxy_send_timeout 300; proxy_read_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; add_header X-Backend "$upstream_addr"; } location ~ /.ht { deny all; }}
关于if 语句
if (){}
要有空格
推荐博客
https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
if 很重要
阅读全文
1 0
- nginx 负载均衡配置
- nginx配置负载均衡
- nginx负载均衡配置
- Nginx负载均衡配置
- Nginx负载均衡配置
- Nginx负载均衡配置
- nginx负载均衡配置
- Nginx 负载均衡配置
- nginx负载均衡配置
- nginx负载均衡配置
- nginx负载均衡配置
- nginx负载均衡配置
- nginx 负载均衡配置
- nginx配置负载均衡
- nginx配置负载均衡
- 配置Nginx负载均衡
- Nginx负载均衡配置
- nginx配置负载均衡
- 大数据分析的两个流程(实时与离线):
- 开发中遇到的垃圾回收
- Linux C++ 串口编程 详解+实例
- 《计算机中可编程内存分析》
- set/multiset map/multimap hash_set/hash_multiset hash_map/hash_multimap 区别与联系
- nginx 负载均衡配置
- 学习J2EE的路途(二)纯干货
- Mac Python环境的配置
- AJAX知识整理
- Python numpy 提取矩阵的某一行或某一列
- android多渠道发布教程(360加固)
- Transform
- Linux系统编程——进程间通信:管道(pipe)
- 选择排序----直接选择排序与堆排序