我已设置 Nginx 上传模块来处理在反向代理模式下在其后面运行的应用程序的文件上传。它在本地工作,但不在服务器 (EC2 Ubuntu AMI) 上工作。我自己编译了 Nginx,其中包含上传模块。这是我的 nginx.conf 的相关部分(来自服务器部分):
location /upload {
# pass request body to here
upload_pass /upload_endpoint;
# Store files to this directory
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
# i.e. make sure to create /u/apps/bugle/shared/uploads_tmp/0 /u /apps/bugle/shared/uploads_tmp/1 etc.
upload_store /tmp/nginxuploads 1;
# set permissions on the uploaded files
upload_store_access user:rw group:rw all:r;
# Set specified fields in request body
# this puts the original filename, new path+filename and content type in the requests params
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";
upload_aggregate_form_field $upload_field_name.size "$upload_file_size";
upload_pass_form_field ".*";
upload_cleanup 400 404 499 500-505;
}
location /upload_endpoint {
proxy_pass http://127.0.0.1:9001;
}
除了 404 之外,日志中没有其他错误,这只是说文件 /usr/local/nginx/html/upload 不存在。知道这里发生了什么吗?
/tmp/nginxuploads/0 至 /tmp/nginxuploads/9 存在并且可以被所有人读取和写入。
答案1
事实证明,对为 Nginx 上传模块设置的端点的 GET 请求将始终返回 404。它可以很好地处理 POST 请求,这当然是您想要的,我只是使用 GET 进行测试!