nginx搭建文件上传下载服务器

黄高爽
2023-12-01

最近要搭建文件一个服务器, 准备使用python的web框架tornado来做。发现了这篇blog,准备使用nginx来实现文件上传和下载的功能。下面把实现步骤记录下来,中间有很多坑。

系统环境:centos6.8

1、下载nginx

wget  http://nginx.org/download/nginx-1.10.2.tar.gz

2、下载nginx upload module

wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz

3、下载nginx-upload-progress-module

git clone https://github.com/masterzen/nginx-upload-progress-module.git

3、编译nginx

./configure --prefix=/usr/local/nginx --with-stream --with-http_image_filter_module --add-module=nginx upload module源码路径 --add-module=nginx-upload-progress-module源码路径 

--with-http_image_filter_module  添加nginx图片处理模块

出现如下错误:./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

4、安装pcre注意使用高版本的, 低版本的一样会出现上面error

我使用的版本是pcre-8.38。安装过程略。安装好pcre后,执行步骤3。

出现如下错误:./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

因为HttpImageFilterModule模块需要依赖gd-devel的支持, 安装gd-devel :yum install gd-devel


5、构建nginx出现错误:

error: no member named 'to_write' in 'ngx_http_request_body_t',在stack overflow有解决方案stackoverflow

具体原因是我们下载的nginx_upload_module-2.2.0.tar.gz不支持nginx 1.4+版本,https://github.com/hongzhidao/nginx-upload-module这个支持最新的nginx版本

6、下载wget https://github.com/hongzhidao/nginx-upload-module/archive/master.zip

7、构建、安装nginx

成功安装nginx

8、可以使用demo测试上传文件的功能了

https://github.com/hongzhidao/nginx-upload-module/blob/master/README.md

http://www.grid.net.ru/nginx/upload.en.html

上传进度获取在下面blog阐述。

 类似资料: