【发布时间】:2013-05-09 07:42:25
【问题描述】:
我的服务器上运行了一个 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()
然后我有 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
注意:我试图取消注释的守护进程(但这不适用于当前使用情况)。
最后,我有这个 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“服务”但作为正常服务运行,我会很高兴。
这是分布信息:
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 内存,其中一半是为这个应用程序保留的.
【问题讨论】:
标签: python nginx webserver uwsgi