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

最近要搭建文件一个服务器, 准备使用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阐述。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
要在 Windows 中搭建一个支持上传和下载文件文件服务器,可以使用 Nginx 和一些插件来实现。以下是步骤: 1. 下载 Nginx for Windows,可以从官网下载:http://nginx.org/en/download.html 2. 解压缩下载Nginx 文件到某个目录下,例如 C:\nginx。 3. 在 C:\nginx\conf 目录下创建一个名为 nginx.conf 的文件,并在其中添加以下配置: ``` worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root C:/nginx/html; index index.html index.htm; autoindex on; } location /upload { client_max_body_size 100m; alias C:/nginx/upload/; autoindex on; dav_methods PUT DELETE MKCOL COPY MOVE; dav_access user:rw group:rw all:r; } } } ``` 这个配置文件中定义了一个 http 服务,监听 80 端口,其中 /upload 路径是用来上传文件的,其它路径是用来下载文件的。注意修改 root 和 alias 的路径为你自己的路径。 4. 在 C:\nginx\html 目录下创建一个名为 index.html 的文件,用于测试下载文件是否成功。 5. 在 C:\nginx\upload 目录下创建一个名为 index.html 的文件,用于测试上传文件是否成功。 6. 启动 Nginx,打开命令行窗口,切换到 C:\nginx 目录下,执行命令:nginx.exe。 7. 打开浏览器,访问 http://localhost/,应该可以看到 index.html 页面,用于测试下载文件是否成功。 8. 打开浏览器,访问 http://localhost/upload/,应该可以看到 index.html 页面,用于测试上传文件是否成功。 现在你的文件服务器已经搭建好了,可以用来上传和下载文件了。上传文件时,可以使用 PUT 方法,例如使用 curl 命令上传文件: ``` curl -T file.txt http://localhost/upload/ ``` 下载文件时,可以使用 GET 方法,例如使用浏览器访问 http://localhost/file.txt。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yongche_shi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值