tom*_*mis 9 python webserver nginx uwsgi
我在我的服务器上运行了一个python应用程序(具体的Django).在昨天之前,它已成功运行在带有mod-wsgi的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()
Run Code Online (Sandbox Code Playgroud)
然后我有init app的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
Run Code Online (Sandbox Code Playgroud)
注意:我已经尝试将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;
}
}
Run Code Online (Sandbox Code Playgroud)
运行该命令uwsgi --ini /etc/uwsgi/apps-enabled/usporion.ini工作正常,我能够看到应用程序在Web上工作.但是,如果我这样做service uwsgi start,服务没有启动(FAIL)没有消息,我在日志中找不到任何东西.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
Run Code Online (Sandbox Code Playgroud)
最后,如果有人想给我一些配置建议(我是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
Run Code Online (Sandbox Code Playgroud)
区别在于wsgi-file,什么替换了旧的module配置值。然后,出现了关于缺少wsgi文件的错误(第一次写入错误)。 daemonize这里没有必要,因为 debian 的服务自动定义了这一点。不过,我认为vacuum,logto那里也没有必要chmod-socket-uwsgi-socket所有这些都是由 debian 的服务定义的。我将批准这一点并完成这个答案。
尽管如此,通过尝试等,这个配置是基本的,其他所有内容都应该自动拒绝或有一些默认值或由 Django 本身拒绝:
[uwsgi]
plugins = python
chdir = /srv/www/usporion
pythonpath = /srv/www/usporion
wsgi-file = /srv/www/usporion/usporion/wsgi.py
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22614 次 |
| 最近记录: |