10

uWSGI を使用して NGINX でボトル アプリケーションをホストしようとしています。

ここに私のnginx.confがあります

location /myapp/ {
        include uwsgi_params;
        uwsgi_param X-Real-IP $remote_addr;
        uwsgi_param Host $http_host;
        uwsgi_param UWSGI_SCRIPT myapp;
        uwsgi_pass 127.0.0.1:8080;
    }

私はこのようにuwsgiを実行しています

uwsgi --enable-threads --socket :8080 --plugin python -- wsgi-file ./myApp/myapp.py

POSTリクエストを使用しています。そのためには、dev Http Client を使用します。リクエストを送信すると無限になります

http://localhost/myapp

uWSGI サーバーがリクエストを受け取り、出力します

[pid: 4683|app: 0|req: 1/1] 127.0.0.1 () {50 vars in 806 bytes} [Thu Oct 25 12:29:36 2012] POST /myapp => generated 737 bytes in 11 msecs (HTTP/1.1 404) 2 headers in 87 bytes (1 switches on core 0)

しかしnginxのエラーログに

2012/10/25 12:20:16 [error] 4364#0: *11 readv() failed (104: Connection reset by peer) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /myApp/myapp/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:8080", host: "localhost"

何をすべきか?

4

4 に答える 4

10

アプリケーションで投稿データを必ず使用してください

たとえば、Django/python アプリケーションがある場合

def my_view(request):

    # ensure to read the post data, even if you don't need it
    # without this you get a: failed (104: Connection reset by peer)
    data = request.DATA

    return HttpResponse("Hello World")

詳細: https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html

于 2014-11-05T19:56:45.173 に答える
7

アプリケーションで読み取ることなく、クライアントからデータを送信することはできません。これは uWSGI では問題になりませんが、nginx では失敗します。uWSGI の --post-buffering オプションを使用して、ソケットからデータを自動的に読み取る (利用可能な場合) ことを「偽造」することはできますが、「修正」することをお勧めします (たとえそれがバグであるとは考えていなくても)。アプリ

于 2012-10-25T07:38:20.100 に答える
5

この問題は、リクエストの本文が消費されていない場合に発生します。これは、uwsgi が、ある時点でまだ必要になるかどうかを判断できないためです。そのため、uwsgi は、データが消費されるか、nginx が接続をリセットするまで (アップストリームがタイムアウトしたため)、データを保持し続けます。

uwsgi の作者がここで説明しています:

08:21 < unbit> plaes: does your DELETE request (not-response) have a body ?
08:40 < unbit> and do you read that body in your app ?
08:41 < unbit> from the nginx logs it looks like it has a body and you are not reading it in the app
08:43 < plaes> so DELETE request shouldn't have the body?
08:43 < unbit> no i mean if a request has a body you have to read/consume it
08:44 < unbit> otherwise the socket will be clobbered

したがって、これを修正するには、常にリクエスト本文全体を読み取るか、必要でない場合 (DELETE など) に本文を送信しないようにする必要があります。

于 2015-03-11T16:35:57.340 に答える
2

スレッドを使用しないでください。

uwsgi の下で Python の Global Interpretator Lock に同じ問題があります。スレッドを使用しない場合-接続のリセットではありません。

uwsgi 構成の例 (サーバー上の 1Gb RAM)

[root@mail uwsgi]# cat myproj_config.yaml 
uwsgi:
    print: Myproject Configuration Started
    socket: /var/tmp/myproject_uwsgi.sock
    pythonpath: /sites/myproject/myproj
    env: DJANGO_SETTINGS_MODULE=settings
    module: wsgi
    chdir: /sites/myproject/myproj
    daemonize: /sites/myproject/log/uwsgi.log
    max-requests: 4000
    buffer-size: 32768
    harakiri: 30
    harakiri-verbose: true
    reload-mercy: 8
    vacuum: true
    master: 1
    post-buffering: 8192
    processes: 4
    no-orphans: 1
    touch-reload: /sites/myproject/log/uwsgi
    post-buffering: 8192
于 2013-02-07T15:54:42.347 に答える