FastDFS+nginx单机配置
引入:文件的下载流程
1、用户下载文件的流程
-
浏览器访问web服务器
-
web服务器调用cgi程序
-
cgi程序需要访问tracker
-
tracker会提供storage的ip和端口
-
cgi程序, 去访问storage,下载数据
-
web服务器需要再次将数据发给浏览器
2、改进下载流程
- 通过浏览器访问web服务器
- 拿到一个地址, 直接通过这个地址, 来访问storage上的图片
3、如何实现?
- 有一个storage服务器
- 在上边部署一个nginx服务器
- 需要在nginx中添加一fastdfs模块
nginx上部署fastDFS模块
- 下载解压fastdfs-nginx-module_v1.16.tar.gz
https://github.com/happyfish100/fastdfs-nginx-module
-
进入到nginx的安装目录
- ./configure --add-module=fastdfs-module的src目录
- ./configure --add-module=/home/lzy/Documents/diskPro/fastdfs-nginx-module-master/src
- make
- sudo make install
-
启动nginx, 只有一个master没有worker
查看nginx的log文件发现/etc/fdfs/目录下没有mod_fastdfs.conf文件,在/home/lzy/Documents/diskPro/fastdfs-nginx-module-master/src目录下找到,执行拷贝命令:sudo cp mod_fastdfs.conf /etc/fdfs/
-
修改模块配置文件
vim mod_fastdfs.conf
-
修改base_path = /home/lzy/fastdfs/storage
-
修改tracker_server=192.168.137.200:22122
-
storage_server_port=23000
-
group_name=group1
-
url_have_group_name = true
-
store_path_count=1
-
store_path0=/home/lzy/fastdfs/storage
-
group_count = 1
-
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/lzy/fastdfs/storage
-
-
不存在http.conf
-
拷贝文件1:/home/lzy/Documents/diskPro/fastdfs/conf/http.conf
cp http.conf /etc/fdfs
-
拷贝文件2:/home/lzy/Documents/diskPro/nginx-1.16.1/conf/mime.types
cp mime.types /etc/fdfs
-
-
重启nginx,此时worker和master进程都有了
-
配置nginx
添加location
location /group1/M00{
root /home/lzy/fastdfs/storage/data;
ngx_fastdfs_module;
}
此时即可直接通过url访问到storage中的图片(storage图床)