nginx+fastdfs 502异常解决
来源:互联网 发布:如何催乙方进度 知乎 编辑:程序博客网 时间:2024/05/29 18:16
使用fastdfs加两台storage,一台做备份使用时,发现有一类文件名是以“ag-”开头,使用<img>标签即时显示的时候会报502异常,
查看nginx的error.log得到
2017/09/25 17:39:09 [error] 13333#0: *30734 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.24.169.19, server: localhost, request: "GET /group1/M00/01/5E/ag-JjlnIzqmAdi3UAAOreY6LKcM688.jpg HTTP/1.1", upstream: "http://106.15.137.142:8081/group1/M00/01/5E/ag-JjlnIzqmAdi3UAAOreY6LKcM688.jpg?redirect=1", host: "10.135.237.203:8081"
分析一下客户端与nginx的交互过程如下:
一般Nginx与Tracker装在一台服务器上,所以他们之间的通信一般不会时间太长而导致超时
但是Nginx与Storage一般不再一台机器上,因此Nginx与Storage之间的通信可能会timeout,从而导致502异常。
所以需要在Nginx中添加如下配置
location /group1/M00{
add_header Content-Disposition "attachment;filename=$arg_n";
add_header Access-Control-Allow-Origin "*";
root /home/ubuntu/fastdfs/nginx-link/data;
ngx_fastdfs_module;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
后来发现,还是解决不了这个问题,继续分析发现另外一台的Storage上的文件是访问不了的,检查一看nginx_fastdfs_module没有配置,添加上去后,重启nginx,发现502的异常解决了但是偶尔会出现插入的图片需要很长时间才能显示出来。
讲过一番思考后,发现这是Storage同步延迟的结果,大概是这样的Tracker将文件放在StorageA上,但是访问的时候,Tracker发现StorageB也是可用的,就返回了StorageB的IP与端口。但是此时StorageB还没有此文件,所以一直等待,直到StorageB同步StorageA的数据。
查看Tracker的配置文件有如下配置:
# which storage server to download file
# 0: round robin (default)
# 1: the source storage server which the current file uploaded to
download_server=1
意思是选择哪一个Storage 服务器去下载文件0代表轮询,为默认值,1代表从当前文件的源文件服务器上下载文件
此时设为1,就好了。
那么Tracker是怎么判断哪一台是源务器的呢?是根据文件名,Tracker_Nginx_Module可以根据文件名反解出源服务器IP,文件时间戳,根据这两点就可以找到源Storage服务器了。
参考:1.http://www.bubuko.com/infodetail-1873115.html
2.http://blog.csdn.net/mr_smile2014/article/details/52118541
- nginx+fastdfs 502异常解决
- Nginx + FastDFS
- fastdfs nginx
- Nginx+FastDFS
- fastDFS+nginx
- Fastdfs+nginx
- fastdfs+nginx+fastdfs-nginx-module
- FastDfs (二) Nginx 整合 Fastdfs
- 【fastDFS】Nginx+FastDFS module安装
- FastDFS+nginx+fastdfs-nginx-module服务器配置
- FastDFS+nginx+fastdfs-nginx-module服务器配置
- centos安装FastDFS+Nginx
- fastdfs+nginx安装详解
- nginx下配置FastDFS
- FastDFS之nginx插件
- FastDfs+nginx环境配置
- FastDfs+nginx环境配置
- fastdfs+nginx安装配置
- android setTextColor setImageResource setBackgroundResource
- css笔记
- jsp界面获取Struts action中的参数值
- 安装redmine部分问题过程详解
- Js-Jquery 网页抢购
- nginx+fastdfs 502异常解决
- 对不起,我的博客
- mysql timeStamp默认值0000-00-00 00:00:00 报错
- 吴恩达Coursera深度学习课程 DeepLearning.ai 提炼笔记(1-4)-- 深层神经网络
- Photon_使用NHibernate中事物防止脏数据_007
- java字符串去掉空格
- My first code--login interface
- git客户端工具sourceTree 无需安装需要注册atlassian账号
- BeagleBone Black 从零到一 (2 MLO、U-Boot)