tornado + nginx upload module 上传文件之后 后端无法接受都niginx发回的参数回传 500 Internal Server Error
在浏览器打开开发者工具发现,它的上传的地址是这样的
打开一个正常访问的网页,比较他们的参数
对比两者发现,他们的不同就在于remote address这里,第一个是想8003端口发送数据,第二个是往80端口发送数据。经验证,因为使用的nginx upload module这个插件,上传的文件会先从nginx 80端口走到后台tornado 8003端口,但是在后台的tornado 8003端口并没有收到任何请求信息。
问题肯定是处在nginx了,去查看一个nginx的
`cd /var/log/nginx`
`sudo cat error.log`
最近一条错误信息如下
```
2020/05/21 16:30:00 [error] 44356#0: *53 could not find named location "http://127.0.0.1:8003/upload", client: 127.0.0.1, server: 127.0.0.1, request: "POST /upload HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/data/upload/"
```
错误信息提示,重点在标红的信息,这里说明我们的所在。经查看http://127.0.0.1:8003/upload,
访问这个连接http://127.0.0.1:8003/upload,确实是可以访问的,并且后台也能看到值,为什么nginx无法回传回去呢?
只能再去看看nginx的配置文件,经过折腾发现是poss_proxy出现了问题,最终将配置文件改为:
`````
location /upload{
# Pass altered request body to this location
#upload_pass @test;
#tornado 访问地址
upload_pass @backend;
upload_pass_args on;
# 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;
upload_store /tmp/dmomb_tmp;
# 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$";
upload_pass_form_field "^.*$";
upload_cleanup 400 404 499 500-505;
}
location @backend {
proxy_pass http://127.0.0.1:8003;
}
`````
然后再运行,后端终于可以收到前端的数据了。