如何配置python + uwsgi + nginx? [英] How to configure python+uwsgi+nginx?
本文介绍了如何配置python + uwsgi + nginx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用uwsgi + nginx运行python脚本. 它在浏览器中导致此错误:
I'm trying to run a python script with uwsgi+nginx. It caused this error in the browser:
uWSGI Error
Python application not found
在var/log/uwsgi/app/pyec.loc.log
中,字符串为:
Sun Mar 3 01:34:36 2013 - added /home/lunochkinma/py_projects/pyec/ to pythonpath.
Sun Mar 3 01:34:36 2013 - mounting hello on /home/lunochkinma/py_projects/pyec/
Sun Mar 3 01:34:36 2013 - *** no app loaded. going in full dynamic mode ***
Sun Mar 3 01:34:36 2013 - *** uWSGI is running in multiple interpreter mode ***
我的uwsgi应用配置:
My uwsgi app config:
<uwsgi>
<plugin>python</plugin>
<socket>/run/uwsgi/app/pyec.loc/pyec.loc.socket</socket>
<pythonpath>/home/lunochkinma/py_projects/pyec</pythonpath>
<app mountpoint="/">
<script>hello</script>
</app>
<master/>
<processes>4</processes>
<harakiri>60</harakiri>
<reload-mercy>8</reload-mercy>
<cpu-affinity>1</cpu-affinity>
<stats>/tmp/stats.socket</stats>
<max-requests>2000</max-requests>
<limit-as>512</limit-as>
<reload-on-as>256</reload-on-as>
<reload-on-rss>192</reload-on-rss>
<no-orphans/>
<vacuum/>
</uwsgi>
Python wsgi文件:
Python wsgi file:
# /home/lunochkinma/py_projects/pyec/hello.py
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return b'Hello World!'
Nginx配置:
server {
listen 80;
server_name paec.loc;
access_log /var/log/nginx/pyec.loc.access.log;
error_log /var/log/nginx/pyec.loc.error.log;
location / {
uwsgi_pass unix:///run/uwsgi/app/pyec.loc/pyec.loc.socket;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
}
location /static {
root /home/lunochkinma/py_projects/pyec/static/;
index index.html index.htm;
}
}
软件:ubuntu 12.04,nginx 1.2.1,uwsgi 1.4.8,python 3.2.3
Soft: ubuntu 12.04, nginx 1.2.1, uwsgi 1.4.8, python 3.2.3
推荐答案
(Answered in a question edit. Converted to a community wiki answer. See What is the appropriate action when the answer to a question is added to the question itself? )
OP写道:
通过向uwsgi应用程序配置参数模块"中添加来解决该问题:
The problem is solved by adding to uwsgi app config parameter "module":
<uwsgi>
<plugin>python</plugin>
<socket>/run/uwsgi/app/pyec.loc/pyec.loc.socket</socket>
<pythonpath>/home/lunochkinma/py_projects/pyec</pythonpath>
<app mountpoint="/">
<script>hello</script>
</app>
<module>hello</module>
<master/>
<processes>4</processes>
<harakiri>60</harakiri>
<reload-mercy>8</reload-mercy>
<cpu-affinity>1</cpu-affinity>
<stats>/tmp/stats.socket</stats>
<max-requests>2000</max-requests>
<limit-as>512</limit-as>
<reload-on-as>256</reload-on-as>
<reload-on-rss>192</reload-on-rss>
<no-orphans/>
<vacuum/>
</uwsgi>
这篇关于如何配置python + uwsgi + nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文