Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python uWSGI服务器没有响应_Python_Django_Linux_Debian_Uwsgi - Fatal编程技术网

Python uWSGI服务器没有响应

Python uWSGI服务器没有响应,python,django,linux,debian,uwsgi,Python,Django,Linux,Debian,Uwsgi,我正在尝试使用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 "

我正在尝试使用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输出静音(初始信息除外):

连接实际上已经建立,因为杀死uWSGI会中止wget

可能uWSGI对发生的错误不够详细,或者我肯定错过了什么。 如果您有任何进一步了解的建议,我们将不胜感激

更新: 更多系统细节:Debian6.0.7,Python2.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)

我从来没有写过一个简单的WSGI应用程序,但看看各种教程,似乎你应该返回一个列表或生成器:或者

return ['Hello world']


对于那些可能也会遇到这个问题的人,以下是我调查的最终结果: 这个问题肯定与环境有关,而且很可能与Linux内核有关。 strace util显示uWSGI无法接收单个字节——这是内核级别的

我认为关键是

os: Linux-2.6.27-ovz-4
Linux在虚拟环境中运行,2.6.27不是Debian 6.0.7的默认内核版本。在2.6.32-5中,一切都很完美


我不知道这是旧内核的bug,还是uWSGI兼容性的bug,或者两者兼而有之。但是更新内核会有所帮助。

在使用
pip
安装uwsgi后,我遇到了同样的问题,症状完全相同

我通过从tarball重新安装uwsgi解决了这个问题,即根据with

wgethttp://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
光盘
制作
这产生了一个uwsgi二进制文件,当用于运行您提到的文档示例时,打印的日志与所用python版本中基于pip的版本uwsgi的日志不同——可执行版本是相同的
(uwsgi 2.0.13.1,64位)
。基于tarball的版本使用Python 2.7.6,而基于pip的版本使用Python 3.4.3。默认安装的版本,即
/usr/bin/python
符号链接指向的版本,在我的系统上是python 2.7.6

事实证明,这根本不是巧合,因为临时将
/usr/bin/python
链接更改为python 3.4.3(并更改了python 3的
test.py
中的返回对象),使得基于pip的可执行文件可以工作


底线是,您应该检查uwsgi日志中的Python版本是否与系统的默认版本一致。我并不是说从tarball安装要比从pip安装好;我猜这是巧合,一个源代码有正确的Python版本,而另一个没有。所以解决这个问题的一种方法是尝试另一种方法来安装uwsgi

,我从中学习了这个例子,所以它应该可以工作。在最坏的情况下,它会导致异常。请报告完整的uWSGI启动日志,您报告的示例应该适用于所有地方(除非您使用的是需要不同返回对象的python3),但可能还有其他问题。从您描述的情况来看,您的系统上似乎安装了某种防火墙,但在127.0.0.1上会很奇怪。。。
yield 'Hello world'
os: Linux-2.6.27-ovz-4
wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd <dir>
make