[英]How to get uwsgi working with nginx and Django 1.7?
这是我尝试的:
我在/etc/nginx/sites-available/
有一个django.conf
upstream django {
server unix:///tmp/uwsgi.sock;
}
server {
listen 80;
server_name weasyprint.django.dev;
charset utf-8;
error_log /var/log/nginx/django-weasyprint.log;
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
然后在sites-enabled
执行sudo ln -s /etc/nginx/sites-available/django.conf
然后我重新启动了nginx。
我在/var/virtual/WebApps/virtualenvs/WeasyPrintProject
创建了一个名为weasyprint_site
的django文件夹
我在同一文件夹上使用了virtualenv,所以现在我的结构是这样的:
WeasyPrintProject
|---------bin
|---------include
|---------lib
|---------local
|---------share
|---------weasyprint_site
|------------db.sqlite3
|------------manage.py
|------------test.py
|------------uwsgi.ini
|------------weasyprint_site
然后我也将uwsgi.ini
放到uwsgi.ini
如您所见。
其内容是:
[uwsgi]
socket=/tmp/uwsgi.sock
chmod-socket=666
uid = www-data
gid = www-data
chdir=/var/virtual/WebApps/virtualenvs/WeasyPrintProject
module=weasy_print.wsgi:application
master=true
pidfile=/var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasy_print.pid
vacuum=true
当我在/var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasyprint_site
,
我跑
uwsgi --ini uwsgi.ini
我得到以下内容:
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.9 (64bit) on [Thu Feb 19 11:59:12 2015] ***
compiled with version: 4.8.2 on 16 February 2015 05:39:16
os: Linux-3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014
nodename: vagrant-ubuntu-trusty-64
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasyprint_site
writing pidfile to /var/virtual/WebApps/virtualenvs/WeasyPrintProject/weasy_print.pid
detected binary path: /var/virtual/WebApps/virtualenvs/WeasyPrintProject/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /var/virtual/WebApps/virtualenvs/WeasyPrintProject
your processes number limit is 15934
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1915160
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named weasy_print.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1913)
spawned uWSGI worker 1 (pid: 1914, cores: 1)
我有2个问题:
我按照这里的指示
我为此特定项目的virtualenv
是使用python 2.7.4,而我正在尝试运行django 1.7。 环境是Ubuntu 14.04
我如何使Django应用程序正常工作。
首先,您正在进入WeasyPrintProject,但是您的项目在WeasyPrintProject / weasyprint_site中。 您应该将chdir放入uwsgi.ini文件中的该目录。
其次,您的项目名称是weasyprint_site,而不是weasy_print,因此您应该改为调用模块weasyprint_site.wsgi:application
。
最后一个问题是:您应该在uwsgi.ini中指定虚拟环境的路径,因此uwsgi进程现在可以在其中找到应用程序所需的其他软件包。
要在不中断uwsgi服务器的情况下返回控制台,必须将其置于后台,通过分叉,守护进程或直接从init脚本启动。 我个人建议使用wsgi中内置的皇帝/封臣制度。
不建议将项目放在virtualenv目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.