如何让 uwsgi 与 nginx 和 Django 1.7 一起工作?
How to get uwsgi working with nginx and Django 1.7?
这是我试过的:
我里面有一个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,所以现在我的结构是这样的:
WeasyPrintProject
|---------bin
|---------include
|---------lib
|---------local
|---------share
|---------weasyprint_site
|------------db.sqlite3
|------------manage.py
|------------test.py
|------------uwsgi.ini
|------------weasyprint_site
然后我也放了一个 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 个问题:
- 除非按 Ctrl+C
,否则我无法返回 bash
- 导入错误提示没有名为 weasy_print.wsgi
的模块
我按照 here
中的说明进行操作
我对这个特定项目的 virtualenv
是使用 python 2.7.4,我正在尝试 运行 django 1.7。环境是Ubuntu14.04
如何让 django 应用程序工作。
首先,您正在 chdiring 到 WeasyPrintProject,但您的项目在 WeasyPrintProject/weasyprint_site 中。您应该 chdir 进入 uwsgi.ini 文件中的那个目录。
其次,您的项目名称是weasyprint_site,而不是weasy_print,因此您应该调用模块weasyprint_site.wsgi:application
。
最后一个问题是:您应该在 uwsgi.ini 中指定您的 virtualenv 的路径,这样 uwsgi 进程现在可以在您的应用程序需要的附加包所在的位置。
为了 return 到您的控制台而不中断您的 uwsgi 服务器,您必须将它置于后台,通过分叉它、守护它或简单地从 init 脚本启动。我个人推荐使用 wsgi 内置的 emperor/vassals 系统。
也不建议将您的项目放在 virtualenv 目录中。
这是我试过的:
我里面有一个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,所以现在我的结构是这样的:
WeasyPrintProject
|---------bin
|---------include
|---------lib
|---------local
|---------share
|---------weasyprint_site
|------------db.sqlite3
|------------manage.py
|------------test.py
|------------uwsgi.ini
|------------weasyprint_site
然后我也放了一个 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 个问题:
- 除非按 Ctrl+C ,否则我无法返回 bash
- 导入错误提示没有名为 weasy_print.wsgi 的模块
我按照 here
中的说明进行操作我对这个特定项目的 virtualenv
是使用 python 2.7.4,我正在尝试 运行 django 1.7。环境是Ubuntu14.04
如何让 django 应用程序工作。
首先,您正在 chdiring 到 WeasyPrintProject,但您的项目在 WeasyPrintProject/weasyprint_site 中。您应该 chdir 进入 uwsgi.ini 文件中的那个目录。
其次,您的项目名称是weasyprint_site,而不是weasy_print,因此您应该调用模块weasyprint_site.wsgi:application
。
最后一个问题是:您应该在 uwsgi.ini 中指定您的 virtualenv 的路径,这样 uwsgi 进程现在可以在您的应用程序需要的附加包所在的位置。
为了 return 到您的控制台而不中断您的 uwsgi 服务器,您必须将它置于后台,通过分叉它、守护它或简单地从 init 脚本启动。我个人推荐使用 wsgi 内置的 emperor/vassals 系统。
也不建议将您的项目放在 virtualenv 目录中。