如何让uwsgi使用nginx和Django1.7?

2024-06-16 10:31:44 发布

您现在位置:Python中文网/ 问答频道 /正文

这就是我所尝试的:

我有一个django.conf里面/etc/nginx/sites-available/

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,所以现在我的结构是这样的:

^{pr2}$

然后我还放了一个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)

我有两个问题:

  1. 我不能回到bash,除非我使用Ctrl+C
  2. 有一个导入错误,说明没有名为weasy的模块_打印.wsgi在

我按照here中的说明操作

对于这个特定的项目,我的virtualenv是使用python2.7.4,我正试图运行django1.7。环境是ubuntu14.04

如何让django应用程序工作。在


Tags: todjangoserverisvarvirtualnginxvirtualenvs
1条回答
网友
1楼 · 发布于 2024-06-16 10:31:44

首先,您将进入WeasyPrintProject,但是您的项目位于WeasyPrintProject/weasyprint_站点。你应该在你的uwsgi.ini文件文件。在

其次,您的项目名是weasyprint_site,而不是weasy_print,因此您应该调用模块weasyprint_site.wsgi:application。在

最后一个问题是:您应该在内部指定到virtualenv的路径uwsgi.ini文件,所以uwsgi进程现在可以将应用程序所需的附加包放在哪里。在

要返回控制台而不中断uwsgi服务器,必须将其置于后台,方法是对其进行分叉、守护进程或简单地从init脚本启动。我个人使用wsgi内置的皇帝/附庸系统重新编译。在

也不建议将您的项目放在virtualenv目录中。在

相关问题 更多 >