测试 uwsgi 报错

2016-08-23 13:19:52 +08:00
 tmackan

最近在用 uwsgi+nginx+virtualenv 部署一个项目

测试 uwsgi

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

然后在 cmd 在运行 uwsgi --http :8001 --wsgi-file /alidata/websites/LandsBLog/test.py&

显示:

***Starting uWSGI 2.0.13.1 (64bit) on [Tue Aug 23 13:16:46 2016] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-4) on 19 August 2016 14:24:34
os: Linux-3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015
nodename: iZ230ph83b2Z
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /alidata/websites/LandsBLog
detected binary path: /root/.virtualenvs/blog/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7283
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8001 fd 4
spawned uWSGI http 1 (pid: 2399)
uwsgi socket 0 bound to TCP address 127.0.0.1:45777 (port auto-assigned) fd 3
Python version: 3.4.1 (default, Aug 19 2016, 10:38:55)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x25ccb10
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x25ccb10 pid: 2398 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 2398, cores: 1)

正常情况下,通过浏览器访问 ip:8001 ,会显示 Hello World 但是我目前什么也不显示 求大神解答。

8938 次点击
所在节点    Python
19 条回复
tmackan
2016-08-23 13:26:23 +08:00
--wsgi-file /alidata/websites/LandsBLog/test.py

路径没有问题
tmackan
2016-08-23 13:47:09 +08:00
uwsgi 安装方式:
pip install uwsgi
tmackan
2016-08-23 13:48:46 +08:00
当我浏览器中输入 ip:8001 时, cmd 显示信息如下:
```[pid: 2444|app: 0|req: 11/11] 123.121.1.79 () {38 vars in 667 bytes} [Tue Aug 23 13:47:34 2016] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (11 switches on core 0)
[pid: 2444|app: 0|req: 12/12] 123.121.1.79 () {36 vars in 594 bytes} [Tue Aug 23 13:47:35 2016] GET /favicon.ico => generated 0 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (11 switches on core 0)
```
tmackan
2016-08-23 14:13:32 +08:00
在服务器 cmd 下运行
curl -i 'http://127.0.0.1:8001/'
显示:
HTTP/1.1 200 OK
Content-Type: text/html

并没有显示 hello world
bdbai
2016-08-23 15:07:26 +08:00
return ["Hello World"]
lovepython
2016-08-23 15:13:05 +08:00
你的返回值不对, return 我记得是可迭代的
tmackan
2016-08-23 15:19:29 +08:00
@lovepython
python 中字符串本身就是可以迭代的
tmackan
2016-08-23 16:03:57 +08:00
@bdbai 试了 不行呀
csdreamdong
2016-08-23 17:55:10 +08:00
贴一下 uwsgi 的配置呗。
csdreamdong
2016-08-23 17:56:27 +08:00
- -。。没仔细看。。要把 virtualevn 的路径加到。。 uwsgi 的启动项里。
csdreamdong
2016-08-23 17:57:58 +08:00
tmackan
2016-08-23 18:36:45 +08:00
@csdreamdong
我是在已经开启了虚拟环境的情况下,运行 uwsgi --http :8001 --wsgi-file /alidata/websites/LandsBLog/test.py&命令的
日志也显示, uwsgi 和 python 都是虚拟环境中所对应的,而不是 system-side 的。
wang9571
2016-08-23 21:07:35 +08:00
return [b"Hello World"]
要返回 bytes 型列表
tmackan
2016-08-23 21:23:53 +08:00
@wang9571 非常感谢,此为正解
tmackan
2016-08-26 13:41:23 +08:00
@wang9571
又出现另一个问题,麻烦看下
http://www.v2ex.com/t/301307#reply2
感谢
wang9571
2016-08-26 14:12:15 +08:00
@tmackan 额~~其实我只是一个初学者,还没用过 uwsgi ,这个帖子的问题并不涉及 uwsgi 我才碰巧答出来~~~
tmackan
2016-08-26 14:22:43 +08:00
@wang9571
嗯 但是有的教程中
不用指明 hello world 字符串转为 bytes 型也行
咳 也是醉了 我快被部署折腾疯了
wang9571
2016-08-26 14:37:06 +08:00
@tmackan 不指明可能是因为那些教程适合 python2 版本的吧?我测试过: python3 必须是 bytes 型, python2 字符串与 bytes 型都可以
tmackan
2016-08-26 15:18:17 +08:00
@wang9571
ok ,明白了,那应该是版本问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/301162

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX