源码安装Nginx+upload上传限速

1.安装依赖

[root@centos software]# yum install pcre pcre-devel gcc gcc-c++ zlib zlib-devel openssl openssl-devel wget -y

2.下载nginx源码包

[root@centos software]# wget -c https://nginx.org/download/nginx-1.12.0.tar.gz

#根据所需下载相应版本 这里已1.12.0版本为例

3.安装nginx

1.#解压
[root@centos software]# tar -xvf nginx-1.12.0.tar.gz 

2.进入解压的nginx路径
[root@centos software]# cd nginx-1.12.0

3.编译(具体模块按需选择)
[root@centos nginx-1.12.0]#  ./configure \
--prefix=/opt/nginx \
--sbin-path=/usr/sbin/nginx  \
--conf-path=/etc/nginx/nginx.conf   \
--error-log-path=/var/log/nginx/error.log  \
--http-log-path=/var/log/nginx/access.log   \
--pid-path=/var/run/nginx.pid   \
--lock-path=/var/run/nginx.lock  \
--http-client-body-temp-path=/var/cache/nginx/client_temp  \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp  \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp  \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp  \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp  \
--user=nginx  \
--group=nginx   \
--with-http_ssl_module  \
--with-http_realip_module  \
--with-http_addition_module  \
--with-http_sub_module  \
--with-http_dav_module  \
--with-http_flv_module  \
--with-http_mp4_module  \
--with-http_gunzip_module  \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module  \
--with-file-aio  \
--with-pcre 

4.[root@centos nginx-1.12.0]# make  &&  make install
5.#版本验证
[root@centos nginx-1.12.0]# /usr/sbin/nginx  -V

可以看到nginx 已安装成功

6.配置system启动请自行查阅相关资料

7.下载upload模块文件

git clone https://github.com/FoNight/nginx_upload_plugin.git

#如网速慢,可以直接下载zip压缩包解压使用

8.新增upload模块

插件路径/home/software/code/nginx_upload_plugin  稍后有用

--add-module=/home/software/code/nginx_upload_plugin  加在上次编译模块之后

切换到nginx编译路径

[root@centos nginx_upload_plugin]# cd /home/software/nginx-1.12.0

配置模块,新增upload

[root@centos nginx-1.12.0]#  ./configure \
--prefix=/opt/nginx \
--sbin-path=/usr/sbin/nginx  \
--conf-path=/etc/nginx/nginx.conf   \
--error-log-path=/var/log/nginx/error.log  \
--http-log-path=/var/log/nginx/access.log   \
--pid-path=/var/run/nginx.pid   \
--lock-path=/var/run/nginx.lock  \
--http-client-body-temp-path=/var/cache/nginx/client_temp  \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp  \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp  \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp  \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp  \
--user=nginx  \
--group=nginx   \
--with-http_ssl_module  \
--with-http_realip_module  \
--with-http_addition_module  \
--with-http_sub_module  \
--with-http_dav_module  \
--with-http_flv_module  \
--with-http_mp4_module  \
--with-http_gunzip_module  \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module  \
--with-file-aio  \
--with-pcre \
--add-module=/home/software/code/nginx_upload_plugin

没报错,继续执行make  && make install

如上图所示,三方模块安装ok

具体upload限速配置

upload_pass 指明后续处理的php地址。文件中的字段将被分离和取代,包含必要的信息处理上传文件。

upload_resumable 是否启动可恢复上传。

upload_store 指定上传文件存放地址(目录)。目录可以散列,在这种情况下,在nginx启动前,所有的子目录必须存在。

upload_state_store 指定保存上传文件可恢复上传的文件状态信息目录。目录可以散列,在这种情况下,在nginx启动前,所有的子目录必须存在。

upload_store_access 上传文件的访问权限,user:r是指用户可读

upload_pass_form_field 从表单原样转到后端的参数,可以正则表达式表示。:

$upload_field_name -- 原始文件中的字段的名称

upload_pass_form_field "^submit$|^description$";

意思是把submit,description这两个字段也原样通过upload_pass传递到后端php处理。如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";

upload_set_form_field 名称和值都可能包含以下特殊变量:

$upload_field_name 表单的name值

$upload_content_type 上传文件的类型

$upload_file_name 客户端上传的原始文件名称

$upload_tmp_path 文件上传后保存在服务端的位置

upload_aggregate_form_field 可以多使用的几个变量,文件接收完毕后生成的并传递到后端

$upload_file_md5 文件的MD5校验值

$upload_file_md5_uc 大写字母表示的MD5校验值

$upload_file_sha1 文件的SHA1校验值

$upload_file_sha1_uc 大写字母表示的SHA1校验值

$upload_file_crc32 16进制表示的文件CRC32值

$upload_file_size 文件大小

$upload_file_number 请求体中的文件序号

这些字段值是在文件成功上传后计算的。

upload_cleanup 如果出现400 404 499 500-505之类的错误,则删除上传的文件

upload_buffer_size 上传缓冲区大小

upload_max_part_header_len 指定头部分最大长度字节。

upload_max_file_size 指定上传文件最大大小,软限制。client_max_body_size硬限制。

upload_limit_rate 上传限速,如果设置为0则表示不限制。

upload_max_output_body_len 超过这个大小,将报403错(Request entity too large)。

upload_tame_arrays 指定文件字段名的方括号是否删除

upload_pass_args 是否转发参数

按需配置即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值