ImportError: No module named mysite.wsgi - uwsgi and nginx settings
ImportError: No module named mysite.wsgi - uwsgi and nginx settings
我在设置生产服务器时遇到问题。到目前为止,我一直在为我的应用程序使用 openshift.com。但现在我创建了一个大数据库的应用程序,1GB 很快就不够用了。因此,我正在将名为 ebook 的应用程序移动到我的 vps 服务器。我尝试使用袜子选项和皇帝模式跟随 this docs。
我安装了 virtualenv、uwsgi 和 nginx。如果我 运行 我的应用程序 ./manage.py runserver ip:port
,我可以在 ip:port.
上查看我的网站
由于 openshift,我有一些奇怪的路径:
虚拟环境路径 /var/www/django/ebook
openshift 项目路径 /var/www/django/ebook/ebook
项目路径 /var/www/django/ebook/ebook/wsgi/ebook
我有 manage.py 和控制器(其中包含 settings.py 文件的应用程序)
然而 运行用 uwsgi 将它连接起来是行不通的。发生导入错误:
ImportError: No module named controller.wsgi
完整的 uwsgi 输出:
[uWSGI] getting INI configuration from ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Mon Apr 13 00:36:54 2015] ***
compiled with version: 4.7.2 on 11 April 2015 12:59:22
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /var/www/django/ebook/ebook
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /var/www/django/ebook/ebook/
your processes number limit is 2062113
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/ebook.sock fd 3
Python version: 2.7.3 (default, Mar 13 2014, 11:26:58) [GCC 4.7.2]
Set PythonHome to /var/www/django/ebook
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x13eb280
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
ImportError: No module named controller.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
virtualenv is active
Traceback (most recent call last):
File "/var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py", line 40, in <module>
application = get_wsgi_application()
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'controller.settings # set an environment variable' (Is it on sys.path? Is there an import error in the settings file?): No module named settings # set an environment variable
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: 7864)
spawned uWSGI worker 1 (pid: 7865, cores: 1)
spawned uWSGI worker 2 (pid: 7866, cores: 1)
spawned uWSGI worker 3 (pid: 7867, cores: 1)
spawned uWSGI worker 4 (pid: 7868, cores: 1)
spawned uWSGI worker 5 (pid: 7869, cores: 1)
spawned uWSGI worker 6 (pid: 7870, cores: 1)
spawned uWSGI worker 7 (pid: 7871, cores: 1)
spawned uWSGI worker 8 (pid: 7872, cores: 1)
spawned uWSGI worker 9 (pid: 7873, cores: 1)
spawned uWSGI worker 10 (pid: 7874, cores: 1)
这是我的 ebook_uwsgi.ini,我 运行 uwsgi 具有:
# ebook_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /var/www/django/ebook/ebook/
# Django's wsgi file
module = controller.wsgi:application
# the virtualenv (full path)
home = /var/www/django/ebook
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /tmp/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
no-site = True
wsgi-file = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
env = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable
和ebook_nginx.conf:
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/ebook.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8001;
# the domain name it will serve for
server_name MY_IP_ADDRESS #.bookdownloading.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/django/ebook/ebook/data; # your Django project's media files - amend as required
}
location /static {
alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass unix:///tmp/ebook.sock;
include /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
}
}
这是我在控制器应用程序中的 wsgi.py 文件:
import sys
activate_this = '/var/www/django/ebook/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import os
if hasattr(sys, 'real_prefix'):
print "virtualenv is active"
sys.path.append("/var/www/django/ebook/lib/python2.7/site-packages/")
sys.path.append("/var/www/django/ebook/ebook/wsgi")
sys.path.insert(0, "/var/www/django/ebook/ebook/wsgi/ebook")
sys.path.append("/var/www/django/ebook/ebook/wsgi/ebook/controller")
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "digrin.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controller.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我有很多 append/insert 命令要 sys.path 因为我不确定哪一个是足够的。我想插入一个应该就够了。
我 运行 为 php 宁阿帕奇,这就是我使用端口 8001 的原因。
应用程序给我 ImportError。知道吗,我错过了什么?
Openshift 结构让我有些困惑。 chdir 应该是:
chdir = /var/www/django/ebook/ebook/wsgi/ebook/
我在设置生产服务器时遇到问题。到目前为止,我一直在为我的应用程序使用 openshift.com。但现在我创建了一个大数据库的应用程序,1GB 很快就不够用了。因此,我正在将名为 ebook 的应用程序移动到我的 vps 服务器。我尝试使用袜子选项和皇帝模式跟随 this docs。
我安装了 virtualenv、uwsgi 和 nginx。如果我 运行 我的应用程序 ./manage.py runserver ip:port
,我可以在 ip:port.
上查看我的网站
由于 openshift,我有一些奇怪的路径:
虚拟环境路径 /var/www/django/ebook
openshift 项目路径 /var/www/django/ebook/ebook
项目路径 /var/www/django/ebook/ebook/wsgi/ebook
我有 manage.py 和控制器(其中包含 settings.py 文件的应用程序)
然而 运行用 uwsgi 将它连接起来是行不通的。发生导入错误:
ImportError: No module named controller.wsgi
完整的 uwsgi 输出:
[uWSGI] getting INI configuration from ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Mon Apr 13 00:36:54 2015] ***
compiled with version: 4.7.2 on 11 April 2015 12:59:22
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
detected number of CPU cores: 8
current working directory: /var/www/django/ebook/ebook
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /var/www/django/ebook/ebook/
your processes number limit is 2062113
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/ebook.sock fd 3
Python version: 2.7.3 (default, Mar 13 2014, 11:26:58) [GCC 4.7.2]
Set PythonHome to /var/www/django/ebook
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x13eb280
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 800448 bytes (781 KB) for 10 cores
*** Operational MODE: preforking ***
ImportError: No module named controller.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
virtualenv is active
Traceback (most recent call last):
File "/var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py", line 40, in <module>
application = get_wsgi_application()
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/django/ebook/local/lib/python2.7/site-packages/Django-1.7-py2.7.egg/django/conf/__init__.py", line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'controller.settings # set an environment variable' (Is it on sys.path? Is there an import error in the settings file?): No module named settings # set an environment variable
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: 7864)
spawned uWSGI worker 1 (pid: 7865, cores: 1)
spawned uWSGI worker 2 (pid: 7866, cores: 1)
spawned uWSGI worker 3 (pid: 7867, cores: 1)
spawned uWSGI worker 4 (pid: 7868, cores: 1)
spawned uWSGI worker 5 (pid: 7869, cores: 1)
spawned uWSGI worker 6 (pid: 7870, cores: 1)
spawned uWSGI worker 7 (pid: 7871, cores: 1)
spawned uWSGI worker 8 (pid: 7872, cores: 1)
spawned uWSGI worker 9 (pid: 7873, cores: 1)
spawned uWSGI worker 10 (pid: 7874, cores: 1)
这是我的 ebook_uwsgi.ini,我 运行 uwsgi 具有:
# ebook_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /var/www/django/ebook/ebook/
# Django's wsgi file
module = controller.wsgi:application
# the virtualenv (full path)
home = /var/www/django/ebook
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /tmp/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
no-site = True
wsgi-file = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
env = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable
和ebook_nginx.conf: # mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/ebook.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8001;
# the domain name it will serve for
server_name MY_IP_ADDRESS #.bookdownloading.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/django/ebook/ebook/data; # your Django project's media files - amend as required
}
location /static {
alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass unix:///tmp/ebook.sock;
include /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
}
}
这是我在控制器应用程序中的 wsgi.py 文件:
import sys
activate_this = '/var/www/django/ebook/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import os
if hasattr(sys, 'real_prefix'):
print "virtualenv is active"
sys.path.append("/var/www/django/ebook/lib/python2.7/site-packages/")
sys.path.append("/var/www/django/ebook/ebook/wsgi")
sys.path.insert(0, "/var/www/django/ebook/ebook/wsgi/ebook")
sys.path.append("/var/www/django/ebook/ebook/wsgi/ebook/controller")
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "digrin.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controller.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我有很多 append/insert 命令要 sys.path 因为我不确定哪一个是足够的。我想插入一个应该就够了。
我 运行 为 php 宁阿帕奇,这就是我使用端口 8001 的原因。
应用程序给我 ImportError。知道吗,我错过了什么?
Openshift 结构让我有些困惑。 chdir 应该是:
chdir = /var/www/django/ebook/ebook/wsgi/ebook/