python - uwsgi 服务没有启动

标签 python nginx webserver uwsgi

我有一个 python 应用程序(具体的 Django)在我的服务器上运行。昨天之前,它在带有mod-wsgi的apache下成功运行,几乎没有问题。我切换到 nginx 的主要原因有两个:

  • 性能——在nginx下,我每个请求几乎有一半的时间
  • 两个应用程序一起在 apache 下运行不成功 - 由 nginx 解决
  • 第三个原因是对我来说更好的配置

我的 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()

然后我有用于初始化应用程序的 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

注意:我曾尝试取消注释 daemonize(但这不适用于当前用法)。

最后,我有这个 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;
    }
}

运行命令 uwsgi --ini/etc/uwsgi/apps-enabled/usporion.ini 运行正常,我能够看到应用程序在网络上运行。但是,如果我执行 service uwsgi start,服务未启动(失败)且没有任何消息,而且我在日志中找不到任何内容。在启用应用程序的情况下,在没有 usporion.ini 的情况下运行此服务工作正常。

如果有任何帮助我可以避免在屏幕下运行 uwsgi“服务”但作为正常服务运行,我会很高兴。

这是 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

最后,如果有人想给我一些配置建议(我是 nginx 的新手,欢迎它),这是 8 核 Xeon 服务器 2.4GHz 和 16GB 内存,其中一半保留给这个应用程序.

最佳答案

错误是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

区别在于 wsgi-file,它替换了旧的 module 配置值。然后,出现关于缺少 wsgi 文件的错误(第一次写入错误)。 daemonize 在这里不是必需的,因为 debian 的服务是自动定义的。不过,我认为 vacuumlogto 以及 chmod-socketuwsgi-socket 都不是必需的 -它们都是由 debian 的服务定义的。我将对此进行验证并完成此回答。

尽管如此,从尝试等来看,这个配置是基本的,其他一切都应该自动定义或具有一些默认值或由 Django 本身定义:

[uwsgi]
plugins = python
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py

关于python - uwsgi 服务没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16553125/

相关文章:

python - 无法停止收到此错误 : ValueError: invalid literal for int() with base 10: ''

javascript - Web 服务器上的 jQuery 要求

java - 正则表达式 - 从字符串中提取数字。数字应该是我输入的前 5 位数字

python - PyQT 4 fnished() 信号不会发出

Django 和 Nginx 深层链接域(重写规则或 django 网址?)

python - 文件在 Django/Nginx 中无法正确下载

kotlin - vert.x 关于网络服务器的概念?

linux - Busybox httpd : error 501 on POST request and cgi not executing on yocto linux-3. 10.53

python - 你如何在 mxnet 中连接符号

.htaccess - 亚马逊弹性 beantalk : Use nginx/apache to forward subdomains to subfolders