nginx 编译安装 nginx-upload-module
安装环境:centos 7
下载 nginx 源码并解压
1
2
3wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2准备编译环境
1
yum install -y gcc automake autoconf libtool make
安装依赖,pcre、openssl、zlib,也可手动编译安装
1
yum install -y pcre pcre-devel zlib zlib-devel openssl open-ssl
配置编译
1
2
3
4
5./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-http_gzip_static_module
常用编译选项说明
- –prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
- –conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
- –user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。–group=name类似
- –with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
- –with-zlib=PATH : 指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
- –with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
- –with-http_stub_status_module : 用来监控 Nginx 的当前状态
- –with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
- –add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)
编译安装
1
make && make install
设置软链接
1
ln -s /usr/local/nginx/nginx /use/sbin/nginx
开始 nginx-upload-module 模块
- nginx 支持文件上传,先看 nginx wiki
按照wiki说明下载 nginx-upload-module 进行编译安装,此处有bug,详见 isuse
即1
2
3
4
5
6
7git https://github.com/fdintino/nginx-upload-module.git
cd nginx-upload-module/
git checkout 2.2
git reset --hard
git clean -f
git pull
git status配置编译
1
2
3
4
5
6./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-http_gzip_static_module \
--add-module=/data/nginx/nginx-upload-module
附录
- nginx-upload-module 配置说明
1 | upload_pass 指明后续处理的地址。文件中的字段将被分离和取代,包含必要的信息处理上传文件。 |