由于php处理上传会出现超时,并且显示上传进度官方php不支持nginx+php,所以决定让nginx自己处理上传,我本地环境是mac上已经安装过nginx1.8.0,安装方式为brew,所以需要重新编译nginx添加upload模块。
nginx下载地址:http://nginx.org/en/download.html
nginx-upload-module下载地址:https://github.com/vkholodkov/nginx-upload-module/tree/2.2
解压nginx
tar xvzf nginx-1.8.0.tar.gz
nginx-upload-module解压目录为:/usr/local/nginx-upload-module-2.2
由于upload模块没有随着nginx的更新出新版本,所以有些地方需要修改,下载补丁文件,地址:http://paste.davromaniak.eu/index.php?show=110
下载文件名为davromaniak.txt,放入/usr/local/nginx-upload-module-2.2目录,执行补丁
cp darvromaniak.txt /usr/local/nginx-upload-module-2.2 patch ngx_http_upload_module.c davromaniak.txt
执行完毕后,开始编译nginx
nginx -V查看已经安装的nginx的版本和编译参数(这是我的nginx参数)
nginx version: nginx/1.8.0 built by clang 6.0 (clang-600.0.57) (based on LLVM 3.5svn) built with OpenSSL 1.0.2a 19 Mar 2015 TLS SNI support enabled configure arguments: --prefix=/usr/local/Cellar/nginx/1.8.0 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.8.0/bin/nginx --with-cc-opt=‘-I/usr/local/Cellar/pcre/8.36/include -I/usr/local/Cellar/openssl/1.0.2a-1/include‘ --with-ld-opt=‘-L/usr/local/Cellar/pcre/8.36/lib -L/usr/local/Cellar/openssl/1.0.2a-1/lib‘ --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module
cd nginx-1.8.0
加上--add-module=/usr/local/nginx-upload-module-2.2(nginx-upload-module解压目录)参数重新编译:
./configure --prefix=/usr/local/Cellar/nginx/1.8.0 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.8.0/bin/nginx --with-cc-opt=‘-I/usr/local/Cellar/pcre/8.36/include -I/usr/local/Cellar/openssl/1.0.2a-1/include‘ --with-ld-opt=‘-L/usr/local/Cellar/pcre/8.36/lib -L/usr/local/Cellar/openssl/1.0.2a-1/lib‘ --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module --add-module=/usr/local/nginx-upload-module-2.2
编译成功后备份旧nginx
cp /usr/local/Cellar/nginx/1.8.0/bin/nginx /usr/local/Cellar/nginx/1.8.0/bin/nginx.bak
把新的nginx程序覆盖旧的
cp /usr/local/nginx-1.8.0/objs/nginx /usr/local/Cellar/nginx/1.8.0/bin/nginx