|
在安装nginx之前, 你可能需要安装一些其他的东西.
诸如:
http_ssl_module
pcre-8.33
zlib-1.2.8
openssl-1.0.1e 你需要一个个的下载并解压
当然最重要的是要集成fastdfs. 首先要下载 fastdfs-nginx-module. 和nginx.
我下载的是fastdfs-nginx-module_v1.15.tar.gz 和nginx1.5.2
安装nginx.
因为我以前上面的东东全部安装了. 我只用了这个命令
./configure
--prefix=/usr/local/nginx
--add-module=/home/songzj/myserver/fastdfs-nginx-module/src/
make
make install
下面是完整版,以便参考:
./configure
--prefix=/usr/local/nginx #指定将nginx安装到/usr/local/nginx目录下.
--sbin-path=/usr/local/nginx #将nginx shell脚本同时安装到/usr/local/nginx下
#.默认只有在sbin中存在
--conf-path=/usr/local/nginx/conf/nginx.conf #配置文件路径
--pid-path=/usr/local/nginx/nginx.pid #pid路径
--with-http_ssl_module #同时集成ssl
--with-pcre=/home/songzj/myserver/pcre-8.33 #集成pcre
--with-zlib=/home/songzj/myserver/zlib-1.2.8 #集成zlib
--with-openssl=/home/songzj/myserver/openssl-1.0.1e #集成openssl
--add-module=/home/songzj/myserver/fastdfs-nginx-module/src/ #集成fastdfs.
make
make install
安装后,需要对一些文件进行配置.
在/usr/local/nginx/conf/nginx.conf中修改 80 为 8080 并增加以下代码
location /group1/M00{
alias /home/songzj/data/fdfs/storage/data;
ngx_fastdfs_module;
}
注意, 下载时发现老报404. 将nginx.conf第一行 usr nobody 修改为 usr root 重新启动后解决.
进行软绑定.
ln -s /home/songzj/data/fdfs/storage/data /home/songzj/data/fdfs/storage/data/M00
复制 /fastdfs-nginx-module/src 下 mod_fastdfs.conf 到 /etc/fdfs/ 目录下.
cp mod_fastdfs.conf /etc/fdfs/
修改/etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.18.244:22122 #本机tracker_server地址.集群时可以配置多台
url_have_group_name = true
store_path0=/home/songzj/data/fdfs/storage
group_count = 1
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/songzj/data/fdfs/storage
#store_path1=/home/yuqing/fastdfs1
启动nginx.
#上传文件
fdfs_test /etc/fdfs/client.conf upload a.txt
#得到file_URL
http://192.168.18.244:8080/group1/M00/00/00/0g6GT1H40jmAZJeWAAAACJr7psA954_big.txt
使用浏览器打开成功. http://192.168.18.244:8080/group1/M00/00/00/0g6GT1H40jmAZJeWAAAACJr7psA954_big.txt
假设: 下载文件时需要将txt文件指定为 测试文件.txt
则后面跟
http://192.168.18.244:8080/group1/M00/00/00/0g6GT1H40jmAZJeWAAAACJr7psA954_big.txt?filename=测试文件.txt
WARN: 可能会出现的问题.
当下载的URL太长, 超过256时, 下载附件会抛出400错误. 跟踪nginx 错误日志得知.
fastdfs_nginx模块. src下 common.c 第615行到622行
if (uri_len + 1 >= (int)sizeof(uri))
{
logError("file: "__FILE__", line: %d, " \
"uri length: %d is too long, >= %d", __LINE__, \
uri_len, (int)sizeof(uri));
OUTPUT_HEADERS(pContext, (&response), HTTP_BADREQUEST)
return HTTP_BADREQUEST;
}
将其删掉. 重新编译,并安装. 重启nginx.
汉字可以扩展到35个汉字. 若超出, 会导致文件下载不完整. 具体原因待查.
|
|
|