1

Nginx + uWSGI を使用して Django アプリケーションを実行しようとしていますが、成功しません。何時間ものグーグルとデバッグの後、動作する必要がある最も単純な uwsgi 構成を作成しました。

$ uwsgi --http 127.0.0.1:8000 --wsgi-file test.py

test.py の場所

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return "Hello World"

問題は、そうではないことです。同じマシンでの wget 呼び出しがハングします。

$ wget http://127.0.0.1:8000
--2013-04-28 12:43:36--  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... 

uWSGI 出力はサイレントです (初期情報を除く):

*** Starting uWSGI 1.9.8 (32bit) on [Sun Apr 28 12:43:56 2013] ***
compiled with version: 4.4.5 on 28 April 2013 06:22:28
os: Linux-2.6.27-ovz-4 #1 SMP Mon Apr 27 00:26:17 MSD 2009
...

uWSGI を強制終了すると wget が中止されるため、接続は実際に確立されます。

おそらく、uWSGI は発生したエラーについて十分に詳しく説明していないか、何かを見逃しているに違いありません。さらに調べる場所のヒントをいただければ幸いです。

アップデート:

システムの詳細: Debian 6.0.7、Python 2.6.6。

開始時の完全な uWSGI ログ:

$ uwsgi --http 127.0.0.1:8000 --wsgi-file test.py
*** Starting uWSGI 1.9.8 (32bit) on [Mon Apr 29 04:50:03 2013] ***
compiled with version: 4.4.5 on 28 April 2013 06:22:28
os: Linux-2.6.27-ovz-4 #1 SMP Mon Apr 27 00:26:17 MSD 2009
nodename: max.local
machine: i686
clock source: unix
detected number of CPU cores: 4
current working directory: /home/user/dir
detected binary path: /home/user/dir/env/ENV/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uWSGI http bound on 127.0.0.1:8000 fd 4
spawned uWSGI http 1 (pid: 19523)
uwsgi socket 0 bound to TCP address 127.0.0.1:57919 (port auto-assigned) fd 3
Python version: 2.6.6 (r266:84292, Dec 27 2010, 00:18:12)  [GCC 4.4.5]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x80f6240
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 63944 bytes (62 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x80f6240 pid: 19522 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 19522, cores: 1)

そして、それ以外は印刷されません。

4

3 に答える 3

2

この問題に遭遇する可能性がある人のために、私の調査の最終結果を次に示します。この問題は間違いなく環境に関連しており、おそらく Linux カーネル固有のものです。strace util は、uWSGI が 1 バイトも受信できないことを示しました。これはカーネル レベルです。

キーラインは

os: Linux-2.6.27-ovz-4

Linux は仮想環境で実行されており、2.6.27 は Debian 6.0.7 のデフォルトのカーネル バージョンではありません。2.6.32-5 では、すべてが完全に機能しました。

古いカーネルのバグなのか、uWSGI 互換性なのか、あるいはその両方なのかはわかりません。ただし、カーネルを更新すると役立ちます。

于 2013-05-02T15:23:52.787 に答える
1

I had the same problem with the exact same symptoms, after having installed uwsgi with pip.

I solved the problem by reinstalling uwsgi from the tarball, i.e. according to the docs with

wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd <dir>
make

This resulted into a uwsgi binary, that when used to run the docs example you mention printed a log that only differed to the log of the pip-based version uwsgi in the python version used -- executable version was the same (uWSGI 2.0.13.1, 64bit). The tarball-based version used Python 2.7.6, while the pip-based version used Python 3.4.3 . The version installed as the default, i.e. the version where the /usr/bin/python symbolic link points to, was Python 2.7.6 on my system.

It turns out that this wasn't at all a coincidence, as changing temporarily the /usr/bin/python link to Python 3.4.3 (and changing the return object in test.py for Python 3), made the pip-based executable work.

The bottom line is that you should check that the Python version at the uwsgi log coincides with the default version of your system. I'm not suggesting that installing from the tarball is better than installing from pip here; my guess that it was coincidental that the one source had the correct Python version while the other didn't. So one way to solve this problem is to try another way to install uwsgi.

于 2016-07-07T14:36:30.857 に答える