Nginx 配置ip_hash
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。
* @author Alan
* @Email no008@foxmail.com
#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 { #设置多个service server_names_hash_bucket_size 64; #-------------Nginx配置ip_hash导致负载均衡算法失效解决方法---------start----------------------------- #真实服务器上一级代理的IP地址或者IP段,可以写多行 set_real_ip_from 127.0.0.1; #从哪个header头检索出要的IP地址 real_ip_header X-Forwarded-For; # 递归排除IP地址,ip串从右到左开始排除set_real_ip_from里面出现的IP,如果出现了未出现这些ip段的IP,那么这个IP将被认为是用户的IP real_ip_recursive on; #-------------Nginx配置ip_hash导致负载均衡算法失效解决方法---------end----------------------------- include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # 使用默认策略,轮询 upstream szsfs { # 下面介绍几种负载均衡策略,其中轮询、weight、ip_hash是nginx内置的,可以直接使用。fair和url_hash需要第三方支持才可以使用。 # 1、轮询(默认):每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。 server 192.168.255.10:18008; server 192.168.255.10:18009; # 2、weight:指定权重,按照权重进行请求的分配。wight和访问比例成正比,适合后端服务器性能不均的情况。 # 下面的配置就会经常访问8288的服务。如果后端服务器8288 down掉,能够立刻切换到8299或者8290。如果8288再次启动,则又能回到原有的权重配置上。8288可以继续提供服务。 # server 192.168.255.10:18008 weight=10; # server 192.168.255.10:18009 weight=1; # 3、ip_hash:每个请求按照ip的hash结果进行分配,这样的话每个访客固定请求一个后端服务器,可以解决session没共享的问题。 # 如果8288 down掉,则依然可以访问,可能会缓存8289或者8290。如果8288启动,则会从8289或8290切换到8288。 ip_hash; # server 192.168.255.10:18008; # server 192.168.255.10:18009; # 4、fair(第三方):后端服务器响应时间短的优先分配。 # fair; # server 192.168.255.10:18008; # server 192.168.255.10:18009; # 5、url_hash(第三方):按访问的url的hash结果来分配请求,这样相同url会分配到相同的后端服务器。适合后端服务器有缓存的情况。 # hash $request_uri; # hash_method crc32; # server 192.168.255.10:18008; # server 192.168.255.10:18009; } ll server { #生产服务器web出口服务器 192.168.255.10:20089 代理 App区 192.168.255.10:20089的配置内容 --->对外转发操作 listen 20089; server_name localhost;# 这里是服务器的IP或者域名 charset utf-8; #charset koi8-r; #access_log logs/host.access.log main; location / { # root html; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; #-------------Nginx配置ip_hash导致负载均衡算法失效解决方法---------start----------------------------- #把原http请求的Header中的Host字段也放到转发的请求里 proxy_set_header Host $http_host; #记录客户端请求的真实IP proxy_set_header X-Real-IP $remote_addr; #用于记录代理信息的,每经过一级代理(匿名代理除外),代理服务器都会把这次请求的来源IP追加在X-Forwarded-For中 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #报头是用于识别协议(HTTP 或 HTTPS) proxy_set_header X-Forwarded-Proto $scheme; #客户端浏览器的主机名 proxy_set_header REMOTE-HOST $remote_host; #其他相关配置入下,可以根据需要添加配置 #允许客户端请求的最大单文件字节数 #client_max_body_size 10m; #缓冲区代理缓冲用户端请求的最大字节数 #client_body_buffer_size 128k; #nginx跟后端服务器连接超时时间(代理连接超时) #proxy_connect_timeout 90; #后端服务器数据回传时间(代理发送超时) #proxy_send_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时) #proxy_read_timeout 90; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 #proxy_buffer_size 4k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 #proxy_buffers 4 32k; #高负荷下缓冲大小(proxy_buffers*2) #proxy_busy_buffers_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传 #proxy_temp_file_write_size 64k; #-------------Nginx配置ip_hash导致负载均衡算法失效解决方法---------end----------------------------- #代理转发 proxy_pass http://szsfs/; #index /pwplogin/toLoginPage.do index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 404 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 192.168.255.10:80 # #location ~ \.php$ { # proxy_pass http://192.168.255.10; #} # pass the PHP scripts to FastCGI server listening on 192.168.255.10:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 192.168.255.10:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } #生产服务器web出口服务器192.168.255.10:20088 短信服务 --->对App区 192.168.255.10:20089进行转发操作 server { listen 20088; server_name localhost; charset utf-8; location / { #root html; # 配置外网App区应用 互联网短信服务器地址信息 proxy_pass https://qydx.53api.com; index index.html index.htm; } } #生产服务器web出口服务器192.168.255.10:20087 微信对账单 --->对App区 192.168.255.10:20089进行转发操作 server { listen 20087; server_name localhost; charset utf-8; location / { #root html; # 配置外网App区应用 调用微信对账单服务器地址信息 proxy_pass https://api.weixin.qq.com; index index.html index.htm; } } #生产服务器web出口服务器192.168.255.10:20086 token校验码 --->对App区进行转发操作 server { listen 20086; server_name localhost; charset utf-8; location / { #root html; # 配置外网app调用 微信对账单服务器地址的token校验码 #proxy_pass https://wap.psbc.com; #生产 proxy_pass https://www.smeia.net; index index.html index.htm; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。 * @author Alan -liu * @Email no008@foxmail.com
转载请标注出处! ✧*꧁一品堂.技术学习笔记꧂*✧. ---> https://www.cnblogs.com/ios9/
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。 * @author Alan -liu * @Email no008@foxmail.com
转载请标注出处! ✧*꧁一品堂.技术学习笔记꧂*✧. ---> https://www.cnblogs.com/ios9/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
2018-01-11 数组 类型 在 存储过程中 使用