使用Apache和mod_wsgi部署的Django产生内部服务器错误500

时间:2019-03-22 06:23:28

标签: django apache2 mod-wsgi

我已经创建了一个Django应用程序,并希望使用apache mod_wsgi进行部署,但是配置出现错误:

  

内部服务器错误500

apache default-ssl.conf

<VirtualHost *:80>
      ServerName my.subdomain.in
      ServerAlias my.subdomain.in
      ServerAdmin webmaster@localhost
      DocumentRoot /home/ubuntu/myproject

      Alias /static/ /home/ubuntu/myproject/static/
      LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

      <Directory /home/ubuntu/myproject/static/>
        Options Indexes FollowSymLinks
        AllowOverride all
        Require all granted
      </Directory>

      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

      <Directory /home/ubuntu/myproject/myproject/wsgi.py>
            Require all granted
      </Directory>

      <Directory /home/ubuntu/myproject/>
        Options Indexes FollowSymLinks
        AllowOverride all
        Require all granted
      </Directory>

      WSGIDaemonProcess my.subdomain.in processes=2 threads=25 python-home=/home/ubuntu/myproject/venv/lib/python3.6 python-path=/home/ubuntu/myproject
      #Pointing wsgi script to config file
      WSGIProcessGroup my.subdomain.in
      WSGIApplicationGroup %{GLOBAL}
      WSGIScriptAlias / /home/ubuntu/myproject/myproject/wsgi.py

</VirtualHost>

wsgi.py

import os
import time
import traceback
import signal
import sys
import site
site.addsitedir('/home/ubuntu/myproject/venv/lib/python3.6/site-packages')
sys.path.append('/home/ubuntu/myproject')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings.prod')

try:
    application = get_wsgi_application()
except Exception:
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

我已经将mod-wsgi模块安装为:sudo apt-get install libapache2-mod-wsgi-py3

编辑

apache错误日志:

[Fri Mar 22 13:06:23.299130 2019] [so:warn] [pid 12668:tid 140168004880256] AH01574: module wsgi_module is already loaded, skipping
[Fri Mar 22 13:06:23.304495 2019] [wsgi:warn] [pid 12669:tid 140168004880256] mod_wsgi: Compiled for Python/3.5.1+.
[Fri Mar 22 13:06:23.304505 2019] [wsgi:warn] [pid 12669:tid 140168004880256] mod_wsgi: Runtime using Python/3.5.2.

[Fri Mar 22 13:06:23.305483 2019] [mpm_event:notice] [pid 12669:tid 140168004880256] AH00489: Apache/2.4.18 (Ubuntu) OpenSSL/1.0.2g mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations 
 [Fri Mar 22 11:41:20.604445 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0] mod_wsgi (pid=7126): TARGET WSGI script '/home/ubuntu/myproject/myproject/wsgi.py' cannot be loaded as Python module.
 [Fri Mar 22 11:41:20.604513 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0] mod_wsgi (pid=7126): Exception occurred processing WSGI script '/home/ubuntu/myproject/myproject/wsgi.py'.
 [Fri Mar 22 11:41:20.609000 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0] Traceback (most recent call last):
 [Fri Mar 22 11:41:20.609026 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0]   File "/home/ubuntu/myproject/myproject/wsgi.py", line 1, in <module>
 [Fri Mar 22 11:41:20.609035 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0]     from django.core.wsgi import get_wsgi_application
 [Fri Mar 22 11:41:20.609058 2019] [wsgi:error] [pid 7126:tid 140321289459456] [remote 112.196.166.119:0] ImportError: No module named 'django'

我在这里想念什么?

谢谢。

0 个答案:

没有答案