2017-05-07 6 views
0

S'il vous plaît aider, je pourrais trouver une erreur. J'utilise django 1.11 et apache (sur CentOS)Déplacez projet Django 1.11 à wsgi

Il est mon wsgi.py

import os 
import sys  
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 
activate_this = os.path.expanduser("/var/project/project_python35_venv/bin/activate_this.py") 
execfile(activate_this, dict(__file__=activate_this)) 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

mon django.conf (httpd)

WSGILazyInitialization On 
WSGIRestrictEmbedded On 
WSGIPassAuthorization On 

WSGIDaemonProcess project user=apache group=apache processes=10 threads=10 maximum-requests=10000 python-path=/var/project/project_python35_venv/lib/python3.5/site-packages python-home=/var/project/project_python35_venv/lib/python3.5 
#WSGIProcessGroup project 
#WSGIApplicationGroup %{GLOBAL} 
#WSGIPythonHome /var/project/project_python35_venv/lib/python3.5 

<VirtualHost *:80> 

<Directory /var/project/project_python35_venv> 
    Require all granted 
</Directory> 

CustomLog /var/log/httpd/project-access.log common 
ErrorLog /var/log/httpd/project-error.log 

DocumentRoot /var/project/project/project/ 

WSGIScriptAlias//var/project/project/project/wsgi.py 

Alias /static /var/project/project/project/static/ 

<Directory /var/project/project/project/static> 
    Require all granted 
</Directory> 

<Directory /var/project/project> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
</Directory> 

</VirtualHost> 

J'essaie tous cas, mais toujours eu cette erreur sur mon journal de httpd:

ImportError: No module named site

Merci à tous pour l'aide

+0

mod_wsgi Est-ce que vous compilez-vous à partir du code source? Comment avez-vous compilé mod_wsgi si vous l'avez fait? Où est l'installation de Python que vous essayez d'utiliser? –

Répondre

0

Essayez cette

wsgi

import os 
import sys 

PROJECT_DIR = '/var/project' 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 
def execfile(filename): 
    globals = dict(__file__ = filename) 
    exec(open(filename).read(), globals) 

activate_this = os.path.join(PROJECT_DIR, 'project_python35_venv/bin', 'activate_this.py') 
execfile(activate_this) 

from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

et apache.conf

WSGILazyInitialization On 
WSGIRestrictEmbedded On 
WSGIPassAuthorization On 

WSGIDaemonProcess project python-path=/var/project/project/:/var/project_python35_venv/lib/python3.5/site-packages/ 
WSGIProcessGroup project 

<VirtualHost *:80> 

<Directory /var/project/project_python35_venv> 
    Require all granted 
</Directory> 

CustomLog /var/log/httpd/project-access.log common 
ErrorLog /var/log/httpd/project-error.log 

DocumentRoot /var/project/project/ 

WSGIScriptAlias//var/project/project/wsgi.py 

Alias /var/project/project/static /var/project/project/static/ 

<Directory /var/project/project/static> 
    Require all granted 
</Directory> 

<Directory /var/project> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
</Directory> 

</VirtualHost> 
+0

Voir http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html pour la manière recommandée d'utiliser les environnements virtuels Python avec mod_wsgi. Vous devriez éviter d'utiliser '' python-path'' avec '' site-packages'', utilisez plutôt '' python-home'' avec la racine de l'environnement virtuel. Lorsque vous avez terminé la configuration d'Apache, vous n'avez pas besoin de '' activate_this'' dans le fichier de script WSGI. –

+0

En outre, définir '' DocumentRoot'' pour être le répertoire ci-dessus où votre code source est une mauvaise idée. Muck up configuration et cela peut signifier que votre code source est téléchargeable. –