最近要搭建文件一個服務器, 準備使用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闡述。