Python uwsgi 服务未启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16553125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uwsgi service is not starting
提问by tomis
I have a python application (concrete Django) running on my server. Before yesterday, it was successfully running under apache with mod-wsgi with almost no problem. I had two main reason to switch to nginx:
我在我的服务器上运行了一个 python 应用程序(具体的 Django)。昨天之前用mod-wsgi在apache下成功运行,几乎没有问题。我有两个主要原因切换到 nginx:
- performance - under nginx, I have almost half time for each request
- two applications together was not running successfully under apache - solved by nginx
- third reason is better configuration for me
- 性能 - 在 nginx 下,我几乎每个请求都有一半的时间
- 两个应用程序一起在 apache 下没有成功运行 - 由 nginx 解决
- 第三个原因是对我来说更好的配置
I have a problem with the uwsgi service. First, I will include the app's wsgi file:
我的 uwsgi 服务有问题。首先,我将包含应用程序的 wsgi 文件:
import os
import sys
path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if path not in sys.path:
sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "usporion.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Then I have uwsgi.ini file for init app, located under /etc/uwsgi/apps-enabled/usporion.ini:
然后我有用于 init 应用程序的 uwsgi.ini 文件,位于/etc/uwsgi/apps-enabled/usporion.ini:
[uwsgi]
plugins = python
uid = www-data
gid = www-data
uwsgi-socket = /srv/sockets/usporion.sock
chmod-socket = 664
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
module = usporion.wsgi
env = DJANGO_SETTINGS_MODULE=usporion.settings
logdate = True
logto = /var/log/uwsgi/usporion.log
#daemonize = /var/log/uwsgi/usporion.log
vacuum = True
max-requests = 1000
processes = 5
threads = 10
workers = 5
vhost = True
Note: I have tried to have daemonize uncommented (but this is not working with current usage).
注意:我曾尝试将 daemonize 取消注释(但这不适用于当前使用情况)。
Lastly, I have this nginx config:
最后,我有这个 nginx 配置:
upstream django {
server 95.168.193.219:80;
}
server {
listen 95.168.193.219:80;
server_name usporion.cz;
return 301 $scheme://www.usporion.cz$request_uri;
}
server {
listen 95.168.193.219:80;
server_name www.usporion.cz;
charset utf-8;
client_max_body_size 100M;
location /media {
alias /srv/www/usporion/media;
expires 1d;
}
location /static {
alias /srv/www/usporion/static;
expires 1d;
}
location / {
root /srv/www/usporion;
include uwsgi_params;
uwsgi_pass unix:///srv/sockets/usporion.sock;
}
}
Running the command uwsgi --ini /etc/uwsgi/apps-enabled/usporion.iniis working fine and I'm able to see app working on the web. However, if I do service uwsgi start, service is not started (FAIL) with no message and I cannot find anything in the logs. Running this service without usporion.iniin apps-enabled is working fine.
运行命令uwsgi --ini /etc/uwsgi/apps-enabled/usporion.ini运行良好,我可以看到应用程序在网络上运行。但是,如果我这样做service uwsgi start,则服务未启动(失败)且没有消息,并且我在日志中找不到任何内容。usporion.ini在不启用应用程序的情况下运行此服务工作正常。
I would be pleased for any help which with I can avoid running uwsgi "service" under screen but run as normal service.
我很乐意提供任何帮助,因为我可以避免在屏幕下运行 uwsgi“服务”但作为正常服务运行。
Here is the dist info:
这是dist信息:
root@[name]:/etc/nginx/sites-enabled# uname -a
Linux [name] 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64 GNU/Linux
root@[name]:/etc/nginx/sites-enabled# cat /etc/debian_version
6.0.7
root@[name]:/etc/nginx/sites-enabled# nginx -v
nginx version: nginx/1.2.6
root@[name]:/etc/nginx/sites-enabled# uwsgi --version
1.2.3-debian
root@[name]:/etc/nginx/sites-enabled# python --version
Python 2.7.3
Lastly, if someone would like to give me some advice to configure (I'm new to nginx and it's welcome), this is 8-core Xeon server 2.4GHz with 16GB of RAM, half of that is reserved for this app.
最后,如果有人想给我一些配置建议(我是 nginx 的新手,欢迎使用),这是 8 核 Xeon 服务器,2.4GHz,16GB RAM,其中一半是为这个应用程序保留的。
采纳答案by tomis
Error is uwsgi configuration:
错误是uwsgi配置:
[uwsgi]
plugins = python
uid = www-data
gid = www-data
uwsgi-socket = /srv/sockets/usporion.sock
chmod-socket = 664
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py
env = DJANGO_SETTINGS_MODULE=usporion.settings
logdate = True
logto = /var/log/uwsgi/usporion.log
#daemonize = /var/log/uwsgi/usporion.log
vacuum = True
max-requests = 1000
master = True
enable-threads = True
processes = 5
threads = 10
vhost = True
Difference is in wsgi-file, what have replaced old moduleconfig value. Then, error about missing wsgi file appeared (first written error). daemonizeis not necessary here as debian's service is automaticly defined this. Still, I think vacuum, logtois not neccessary there, as well chmod-socketand uwsgi-socket- all of them is defined by debian's service. I will aprove this and complete this answer.
不同之处在于wsgi-file,替换了旧的module配置值。然后,出现丢失 wsgi 文件的错误(第一个写入错误)。 daemonize这里没有必要,因为 debian 的服务是自动定义的。尽管如此,我认为vacuum,logto也不是必需的,chmod-socket而且uwsgi-socket- 所有这些都由 debian 的服务定义。我会批准这一点并完成这个答案。
Still, from trying etc., this configuration is basic and everything else should be denifed automaticly or have some default value or by Django itselves:
尽管如此,从尝试等来看,这个配置是基本的,其他一切都应该被自动拒绝或有一些默认值或由 Django 本身:
[uwsgi]
plugins = python
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py

