问题
I have been working on a Django app that I am ready to move to the production server. I have Apache and mod_wsgi installed and I used a test to check to see that it all works, and it does. But now I am having problems getting it to work with Django.
I have created the wsgi.py file:
import os
import os.path
import sys
sys.path.append('/var/www/html/mideastinfo/lib/python2.7/site-packages/django/bin/mideastinfo')
#os.environ['PYTHON_EGG_CACHE'] = 'path to a directory for egg cache'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()
And I have the http.conf point to it via WGSIScriptAlias. It's not working, I know it has to do with the sys.path, I am not sure what to do.
I had a development environment in which I did all the build. Then, I installed all the project dependencies onto the server user pip and a requirements.txt. Then, I moved my project files over. But I think I am getting all the mapping and pathing wrong. Any ideas? I feel like I am one step away from being done with this.
回答1:
I will share how I've configured a simple example:
import os,sys
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append('PATH TO YOUR PROJECT ROOT')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mideastinfo.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
On your VirtualHost directive on Apache config you must have:
WSGIScriptAlias / /PATH/TO/YOUR/.wsgi
Example:
<VirtualHost *:80>
ErrorLog /home/user/logs/error.log
...
WSGIScriptAlias / /PATH/TO/YOUR/.wsgi
...
</VirtualHost>
来源:https://stackoverflow.com/questions/26111122/cannot-deploy-django-on-apache-with-mod-wsgi