http - 如何让 HTTP 服务器 nginx 使用 HTTP 多部分请求上传文件?
问题描述
推荐的 nginx 模块包含在 nginx 的构建中:
https://www.nginx.com/resources/wiki/modules/upload/
nginx.conf 文件:
working_directory /usr/local/nginx;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
client_max_body_size 100m;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
# Upload form should be submitted to this location
location /upload {
# 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
upload_store /tmp 1;
# Allow uploaded files to be read only by user
upload_store_access user:r;
# 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$";
}
# Pass altered request body to a backend
location @test {
proxy_pass http://localhost:8080;
}
}
}
当我尝试上传文件时:
curl -v -i -F "data=audiorecordtext.mp4" http://192.168.1.3
(服务器在我本地的 Intranet 上),nginx 以 404 响应,未找到文件。查看 nginx 日志显示它正在尝试打开
/usr/share/nginx/html/post
这当然不存在。
如何让 Multipart Request 上传与 nginx 一起使用?我在互联网上搜索没有成功。
解决方案
推荐阅读
- excel - 无法在自定义函数中检索单元格值
- python-3.x - 使用 python 获取 AutoCAD AcDbText 对象的文本
- javascript - JS - setInterval 为单个实例运行
- ruby-on-rails - 如何修复不兼容的库版本?
- c# - 错误 CS0116:命名空间不能直接包含字段或方法等成员
- r - 用 R 中的 rvest 刮取一个表标题不匹配的表
- python-3.x - 即使按照几个类似问题中的建议进行修复,也会出现 500 内部服务器错误
- email - 如何在 Mac Os X Server 主机外部路由邮件
- algorithm - 丑数大 O 算法(蛮力法)
- c++ - 在着色器上实现 GL_REPEAT