#Django WSGI
WSGIScriptAlias / /var/www/transfergateway/myproject/wsgi.py
WSGIPythonPath /var/www/transfergateway
<VirtualHost *:443>
ServerName *redacted*
<Directory /var/www/transfergateway>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
#test chroot jail for Django WSGI
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:443>
ServerName *redacted*
WSGIScriptAlias / /var/chroot/var/www/transfergateway/myproject/wsgi.py
WSGIProcessGroup chroot
WSGIDaemonProcess chroot user=daemon group=daemon processes=2 threads=25 chroot=/var/chroot
<Directory /var/chroot/var/www/transfergateway/myproject/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
But I am getting the following errors in the Apache error log upon startup:
Target WSGI script '/var/www/transfergateway/myproject/wsgi.py' cannot be loaded as Python module.
Exception occurred processing WSGI script '/var/www/transfergateway/myproject/wsgi.py'.
Traceback (most recent call last):
File "/var/www/transfergateway/myproject/wsgi.py", line 29, in <module>
from django.core.wsgi import get_wsgi_application
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 1, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 9, in <module>
from django import http
File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
File "/usr/local/lib/python2.7/dist-packages/django/http/cookie.py", line 3, in <module>
from django.utils.encoding import force_str
File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 4, in <module>
import datetime
ImportError: No module named datetime
I appreciate any advice on what I am doing wrong here. Do I have my chroot set up properly? Do I need to do anything with permissions on /var/chroot or /var/chroot/var/www/transfergateway? Do I need to run mod_wsgi as a different user than daemon?
thanks in advance for any help!
--Jennifer
--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.
You know, I'm not totally sure about the virtualenv... I am new to Python. We have had a bit of history with two different developers working on this code (and I am not in communication with the first developer). Kind of a difficult spot I'm in, with limited info. The first developer had started out using a virtualenv but I believe switched to using pip to install packages system-wide. I am trying to normalize the package installation so they are all installed the same way and get a list of what packages are in use.(I know this may be out of scope for the group, but if someone can tell me how to determine if a virtualenv is in use, and if so, how to deactivate it and move over to only using system-wide packages, that would be enormously helpful.)
Is the datetime error a separate error from the "Target WSGI" error, or causing it?
Wow. Surprised you got that far. The chroot feature of mod_wsgi pretty well has no documentation. At best there might be some comments about it buried in the release notes somewhere.Before we try and sort out the issue, I might say that the better way of trying to isolate an application these days would be to use Docker. I realise this means learning a bit about how to install and manage Docker, but as far as running Apache/mod_wsgi under Docker, the experience is much much better as I provide a prebuilt Docker image for doing it.This Docker image is something I don't think I have mentioned here on the mod_wsgi mailing list as it has only been out there for a week or so.I have recently started blogging about it and have two posts up about it:The actual Docker Hub entry is:
Anyway, for chroot, can you confirm a few things.First is whether the Python version outside of the chroot is the default operating system Python installation for 2.7 and that the mod_wsgi is also the operating system binary package also.Double check what version of Python mod_wsgi is installed for. I would imagine it should be Python 2.7, but want to make sure isn't 2.6.
sys.version = '2.7.6 (default, Mar 22 2014, 23:03:41) \n[GCC 4.8.2]' sys.prefix = '/usr'
Now inside of the chroot, did you also use the default operating system Python installation for 2.7.Inside of the chroot, run the 'python' command line and see if datetime can imported.$ pythonPython 2.7.2 (default, Oct 11 2012, 20:14:37)[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import datetime>>> datetime.__file__'/Users/graham/Python/docker/lib/python2.7/lib-dynload/datetime.so'
Python 2.7.6 (default, Mar 22 2014, 22:59:38)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.__file__
WSGISocketPrefix /var/run/wsgi
<VirtualHost *:443>
ServerName **redacted***
WSGIScriptAlias / /var/chroot/var/www/transfergateway/myproject/wsgi.py
WSGIProcessGroup chroot
WSGIDaemonProcess chroot user=daemon group=daemon processes=2 threads=25 chroot=/var/chroot python-path=/var/chroot/var/www/transfergateway
<Directory /var/chroot/var/www/transfergateway/myproject/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
"""
WSGI config for myproject project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
import sys
path='/var/www/transfergateway/myproject'
#if path not in sys.path:
#sys.path.append(path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.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()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
mod_wsgi (pid=16343): Target WSGI script '/var/www/transfergateway/myproject/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=16343): Exception occurred processing WSGI script '/var/www/transfergateway/myproject/wsgi.py'.
Traceback (most recent call last):
File "/var/www/transfergateway/myproject/wsgi.py", line 31, in <module> application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setupself._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 98, in __init__% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named myproject.settings
mod_wsgi (pid=17140): Target WSGI script '/var/www/transfergateway/myproject/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=17140): Exception occurred processing WSGI script '/var/www/transfergateway/myproject/wsgi.py'.
Traceback (most recent call last):
File "/var/www/transfergateway/myproject/wsgi.py", line 30, in <module> application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label) ImproperlyConfigured: Application labels aren't unique, duplicates: sessions