天天看點

tornado + nginx upload module 上傳檔案之後 後端無法接受都niginx發回的參數回傳 500 Internal Server Error

tornado + nginx upload module 上傳檔案之後 後端無法接受都niginx發回的參數回傳 500 Internal Server Error

在浏覽器打開開發者工具發現,它的上傳的位址是這樣的

tornado + nginx upload module 上傳檔案之後 後端無法接受都niginx發回的參數回傳 500 Internal Server Error

打開一個正常通路的網頁,比較他們的參數

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;

    }

`````

然後再運作,後端終于可以收到前端的資料了。