2017-04-07 2 views
1

Ich habe Schwierigkeiten zu versuchen, Apache 2.4.7 eine Django 1.8.17-Anwendung mit mod_wsgi 4.5.15 mit Python 3.5.3 als virtuelle Umgebung zu dienen. Dies ist die einzige virtuelle Umgebung, die ich auf dem Rechner habe (Linux Mint 17.3).Probleme Konfigurieren von mod_wsgi mit Virtual Env

Ich bekomme einen "internen Server Error" im Browser.

Mein Apache Fehlerprotokoll sagt:

[Thu Apr 06 19:48:22.530935 2017] [mpm_prefork:notice] [pid 4476] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/4.5.15 Python/3.5 configured -- resuming normal operations 
[Thu Apr 06 19:48:22.531008 2017] [core:notice] [pid 4476] AH00094: Command line: '/usr/sbin/apache2' 
[Thu Apr 06 19:48:28.165360 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Target WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py' cannot be loaded as Python module. 
[Thu Apr 06 19:48:28.165494 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] mod_wsgi (pid=4480): Exception occurred processing WSGI script '/home/magic-rat/ektropy_project/ektropy_project/wsgi.py'. 
[Thu Apr 06 19:48:28.166150 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] Traceback (most recent call last): 
[Thu Apr 06 19:48:28.166210 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/ektropy_project/ektropy_project/wsgi.py", line 16, in <module> 
[Thu Apr 06 19:48:28.166218 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  application = get_wsgi_application() 
[Thu Apr 06 19:48:28.166230 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application 
[Thu Apr 06 19:48:28.166238 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  django.setup() 
[Thu Apr 06 19:48:28.166250 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/__init__.py", line 17, in setup 
[Thu Apr 06 19:48:28.166257 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
[Thu Apr 06 19:48:28.166269 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 48, in __getattr__ 
[Thu Apr 06 19:48:28.166276 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  self._setup(name) 
[Thu Apr 06 19:48:28.166288 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 44, in _setup 
[Thu Apr 06 19:48:28.166295 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  self._wrapped = Settings(settings_module) 
[Thu Apr 06 19:48:28.166307 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/home/magic-rat/virtualenvs/ektropy_project/lib/python3.5/site-packages/django/conf/__init__.py", line 92, in __init__ 
[Thu Apr 06 19:48:28.166314 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  mod = importlib.import_module(self.SETTINGS_MODULE) 
[Thu Apr 06 19:48:28.166325 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module 
[Thu Apr 06 19:48:28.166335 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901]  return _bootstrap._gcd_import(name[level:], package, level) 
[Thu Apr 06 19:48:28.166347 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
[Thu Apr 06 19:48:28.166358 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
[Thu Apr 06 19:48:28.166369 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked 
[Thu Apr 06 19:48:28.166381 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
[Thu Apr 06 19:48:28.166392 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
[Thu Apr 06 19:48:28.166418 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
[Thu Apr 06 19:48:28.166429 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked 
[Thu Apr 06 19:48:28.166464 2017] [wsgi:error] [pid 4480] [remote 127.0.0.1:34901] ImportError: No module named 'ektropy_project' 

Meine Verzeichnisstruktur ist:

home/magic-rat/ 
| 
|__________virtualenvs 
|    | 
|    |-ektropy_project 
|      | 
|      |-lib 
|       | 
|       |-python3.5 
|        | 
|        |-site_packages 
| 
|__________ektropy_project 
        | 
        |-manage.py 
        | 
        |-ektropy_project 
          | 
          |-wsgi.py 
          |-helloworld.wsgi (so you can see where it is) 

Mein Apache virtuelle Host-Datei ist:

<VirtualHost *:8000> 

ServerAdmin [email protected] 
DocumentRoot /var/www/html 

WSGIDaemonProcess ektropy_project python-home=/home/magic-rat/virtualenvs/ektropy_project 

WSGIProcessGroup ektropy_project 
WSGIApplicationGroup %{GLOBAL} 

WSGIScriptAlias//home/magic-rat/ektropy_project/ektropy_project/wsgi.py 

<Directory /home/magic-rat/ektropy_project/ektropy_project> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
</Directory> 

Mein wsgi. PY-Datei s:

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ektropy_project.settings") 

application = get_wsgi_application() 

Ich glaube, mod_wsgi ist richtig konfiguriert. Ich kann ein einfaches hallo_world Programm ausführen und es funktioniert.

Ich glaube, dass Berechtigungen für alle Dateien ordnungsgemäß festgelegt sind.

Jede Hilfe wird geschätzt.

+0

Ihr Nginx sieht gut aus, weil Sie Django Fehlerprotokoll erhalten. Haben Sie Ihre App ohne nginx getestet ('python manage.py runserver')? Ich denke, es ist seltsam, weil Sie nicht das Hauptmodul zu Ihren Einstellungen hinzugefügt haben ... – Rafael

+0

Ja, es funktioniert gut mit dem eingebauten runserver Befehl. I – Pat

Antwort

1

eine zusätzliche Option zu WSGIDaemonProcess von:

python-path=/home/magic-rat/ektropy_project 

Sie haben mod_wsgi zu sagen, wo Ihr Projekt-Code als auch ist, so dass es sie importieren.

+0

Das hat es getan. Vielen Dank! Ich bekomme den dynamischen Inhalt und einige der .css. Ich werde das jetzt herausfinden. Ich bin endlich mit Apache! – Pat

+0

Für statische Dateien siehe https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#serving-files –

Verwandte Themen