简体   繁体   中英

ImportError: No module named mysite.wsgi - uwsgi and nginx settings

I am having trouble setting up my production server. Till now, I was using openshift.com for my apps. But now I created an app with large db and 1GB was quickly not enough. So I am moving my app called ebook to my vps server. I tried to follow this docs with sock option and emperor mode.
I installed virtualenv, uwsgi and nginx. If I run my app with ./manage.py runserver ip:port , I can view my website on ip:port.
Because of openshift I have a little weird paths:
virtualenv path /var/www/django/ebook
openshift project path /var/www/django/ebook/ebook
project path /var/www/django/ebook/ebook/wsgi/ebook where I have manage.py and controller (app with settings.py file in it)

However running it with uwsgi does not work. Import error occured:
ImportError: No module named controller.wsgi
Full uwsgi output:

[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)

this is my ebook_uwsgi.ini that I run uwsgi with:

    # 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

and 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
    }
}

And this is my wsgi.py file in controller app:

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()

I have so many append/insert commands to sys.path because I was not sure which one is enough. I guess insert one should be enough.
I am running apache for php, that is why I use port 8001. App gives me ImportError. Any idea, what am I missing?

Openshift structure confused me a little. chdir should have been:
chdir = /var/www/django/ebook/ebook/wsgi/ebook/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM