1、编译安装nginx

wget https://github.com/fdintino/nginx-upload-module/archive/refs/heads/master.zip

PS:原先使用的nginx-upload-module-2.2编译的时候报错:ngx_http_upload_module.c:14:17: fatal error: md5.h: No such file or directory

后来找到一个可用的fork版本https://github.com/Austinb/nginx-upload-module
我下载得zip包 nginx-upload-module-master.zip
# yum -y install openssl libssl-dev gcc gcc-c++ make
# cd /data
# unzip nginx-upload-module-master.zip
# cd nginx-1.19.9/
# ./configure --prefix=/data/nginx --add-module=../nginx-upload-module-master --with-http_secure_link_module
# make && make install

2、编辑nginx配置文件

vim conf/nginx.conf

#user  nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
client_max_body_size 100m;
location / {
root html;
index index.html index.htm;
}
error_page 405 =200 @405;
# Upload form should be submitted to this location
location /upload { if ($request_method = 'GET'){
root html;
}
if ($request_method = 'POST'){ # Pass altered request body to this location upload_pass @test; # Store files to this directory
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
 #文件存储的路径,要先手动创建0 1 2 3 4 5 6 7 8 9一共10个文件夹
upload_store /data/nginx/html/upload 1; # Allow uploaded files to be read only by user
upload_store_access user:rw; # Set specified fields in request body
upload_set_form_field "${upload_field_name}_name" $upload_file_name;
upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
upload_set_form_field "${upload_field_name}_path" $upload_tmp_path; # Inform backend about hash and size of a file
upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size; upload_pass_form_field "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}
}
# Pass altered request body to a backend location @test {
#content_by_lua ngx.say("upload success!");
proxy_pass http://localhost:8888;
return 200;
} }
}

使用 nginx -t 检测一下配置文件是否正确

我这里遇到一个问题  如果不使用 if 判断 开启uoload_pass @test 的话直接访问页面会报405

创建存储目录和访问的index首页

# mkdir -p html/upload/{0..9}

vim html/upload/index.html

<html>
<head>
<title>Test upload</title>
</head>
<body>
<h2>Select files to upload</h2>
<form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
<input type="file" name="file4"><br>
<input type="file" name="file5"><br>
<input type="file" name="file6"><br>
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="test" value="value">
</form>
</body>
</html>

3、启动nginx

./sbin/nginx

4、浏览器访问 http://192.168.53.100/upload/,结果如下

5、上传文件测试

可以看到选中文件点upload 的时候报出了503,需要修改一下存储目录权限

# chmod 777 {0..9}
[root@localhost upload]# ll
total 4
drwxrwxrwx. 2 root root 6 Mar 14 00:07 0
drwxrwxrwx. 2 root root 6 Mar 14 00:07 1
drwxrwxrwx. 2 root root 6 Mar 14 00:07 2
drwxrwxrwx. 2 root root 6 Mar 14 00:07 3
drwxrwxrwx. 2 root root 6 Mar 15 00:56 4
drwxrwxrwx. 2 root root 6 Mar 15 00:56 5
drwxrwxrwx. 2 root root 6 Mar 14 00:07 6
drwxrwxrwx. 2 root root 6 Mar 14 00:07 7
drwxrwxrwx. 2 root root 6 Mar 14 00:07 8
drwxrwxrwx. 2 root root 6 Mar 14 00:07 9
-rw-r--r--. 1 root root 501 Mar 14 00:14 index.html

重新上传试试  上传成功

我们去服务器查看文件存储位置

6、添加账号登录验证

使用 htpasswd 生成用户密码

# htpasswd -c conf/htpasswd test1
New password:
Re-type new password:
Adding password for user test1

编辑nginx.conf配置文件,在upload下添加

auth_basic    'upload balance file';
auth_basic_user_file htpasswd;

重启nginx,浏览器访问

可以看到现在登录页面需要账号密码验证,使用自己创建的账号密码登录即可

7、服务器使用curl 进行文件上传调试

# curl -v -u 'test1:test1' -F file1=@1.txt -H "Content-Type:multipart/form-data" -H "Content-Disposition:attachment;filename=1.txt" -X POST http://localhost/upload

8、编写文件上传脚本

nginx文件上传模块 nginx_upload_module的更多相关文章

  1. nginx上传模块nginx_upload_module和nginx_uploadprogress_module模块进度显示,如何传递GET参数等。

    ownload:http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gzconfigure and make : . ...

  2. 解决nginx上传模块nginx_upload_module传递GET参数

    解决nginx上传模块nginx_upload_module传递GET参数的方法总结 最近用户反映我们的系统只能上传50M大小的文件, 希望能够支持上传更大的文件. 很显然PHP无法轻易实现大文件上传 ...

  3. 基于SqlSugar的开发框架循序渐进介绍(7)-- 在文件上传模块中采用选项模式【Options】处理常规上传和FTP文件上传

    在基于SqlSugar的开发框架的服务层中处理文件上传的时候,我们一般有两种处理方式,一种是常规的把文件存储在本地文件系统中,一种是通过FTP方式存储到指定的FTP服务器上.这种处理应该由程序进行配置 ...

  4. Nginx文件上传下载实现与文件管理

    1.Nginx 上传 Nginx 依赖包下载 # wget http://www.nginx.org/download/nginx-1.2.2.tar.gzinx # wget http://www. ...

  5. UEditor独立图片、文件上传模块

    百度的UEditor编辑器的强大之处不用多说,但是有时候我们只想用他的文件.图片上传模块,不想把这个编辑器加载出来,话不多说,直接上实现代码: 引用文件: <script src="~ ...

  6. PHP和Nginx 文件上传大小限制问题解决方法

    对于nginx+php的一些网站,上传文件大小会受到多个方面的限制,一个是nginx本身的限制,限制了客户端上传文件的大小,一个是php.ini文件中默认了多个地方的设置. 所以为了解决上传文件大小限 ...

  7. nginx上传模块nginx_upload_module使用

    1.安装模块 1 cd /data/software 2 wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.t ...

  8. express 4.x 文件上传

    1.安装文件上传模块: npm install multiparty --save 2.在routes/index.js 中添加: // 引用模块 let multiparty = require(& ...

  9. 源码解读-文件上传angularFileUpload1

    angular-file-upload 1.文件上传模块的引入就不赘述,简单准备 2.初始化组件并绑定change事件 3.监听用户选择文件FileItem(change事件),push进文件数组qu ...

  10. 使用百度webuploader实现大文件上传

    版权所有 2009-2018荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/up6.2/in ...

随机推荐

  1. vue部署样式错乱

    1 <style scoped> 2 .el-menu-vertical-demo:not(.el-menu--collapse) { 3 border: none; 4 } 5 .sub ...

  2. Mybatis-plus中sql语句各查询条件含义

    lt:less than 小于le:less than or equal to 小于等于eq:equal to 等于ne:not equal to 不等于ge:greater than or equa ...

  3. 将bat文件设置为开机启动

    设置该bat文件开机自启动 1.右键计算机–>管理,选择系统工具–>计划任务程序: 2.选择创建任务,在弹出窗口中,输入任务名称,并选择不管用户是否登录都要运行–>使用最高权限运行: ...

  4. linux 中EOF用法

    EOF是END Of File的缩写,表示自定义终止符.既然自定义,那么EOF就不是固定的,可以随意设置别名,在linux按ctrl-d就代表EOF.EOF一般会配合cat能够多行文本输出.其用法如下 ...

  5. 关于 MySQL 的 General Log 功能

    检查 General Log 输出目标 SHOW GLOBAL VARIABLES LIKE 'log_output'; # Type: Set # Default Value: FILE # Val ...

  6. QT控件使用--QPlainTextEdit

    QPlainTextEdit是一个多行文本编辑器,用于显示和编辑多行简单文本. 一些常用的函数有: appendPlainText(const QString) 向 PlainTextEdit 组件添 ...

  7. 解决在宝塔面板IIS服务器上部署svg/woff/woff2字体的问题

    部署网站的字体和服务器IIS有什么关系?如果你的职责只限于一名前端开发,那么你可能很"幸福"地与这些问题擦肩而过,浑然不觉.可是本人一直都是孤军奋战,连开发环境都要自己搭建,这次又 ...

  8. TCP三次握手四次挥手内容及步骤

    TCP特性 1.工作在传输层 2.面向连接的协议 3.全双工协议 4.半关闭 5.错误检查 6.将数据打包成段,排序 7.确认机制 8.数据恢复.重传 9.流量控制.滑动窗口 10.拥塞控制,慢启动和 ...

  9. Java中创建线程的方式和线程中常用方法?

    Java中如何创建线程? 继承Thread类 实现Rnnable接口 实现Callable接口 通过线程池创建线程 线程中常用方法 线程等待:wait() 进入等待状态,只有等其他线程唤醒或中断才能运 ...

  10. jboss单机环境搭建

    1.操作系统:centos7 2.需要的包:apache,wildfly,postgres(要初始化),activemq 3.安装流程: 一.安装依赖包并部署服务:httpd,wildfly,mq,p ...