[英]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.