LoginSignup
3
1

More than 3 years have passed since last update.

mod_wsgi 500 Internal Server Errorの対処法

Posted at

背景

ApacheをDjangoに接続しようとして設定したところ、Internal Server Errorに遭遇する。
ss19.png

関連記事:Django + Apache with mod_wsgi on Windows Server 2016

環境

  • Windows Server 2016
  • Apache 2.4 + mod_wsgi
  • Django 3.0

調査

Apacheのエラーログを見てみる(自環境ではC:\Apache24\logs\error.logにある)。

error.log
※日時は邪魔なので消しました。
[wsgi:error] [pid 7288:tid 1272] [client ::1:62535] mod_wsgi (pid=7288): Failed to exec Python script file 'D:/apps/shibtest3/shibtest3/wsgi.py'.
[wsgi:error] [pid 7288:tid 1272] [client ::1:62535] mod_wsgi (pid=7288): Exception occurred processing WSGI script 'D:/apps/shibtest3/shibtest3/wsgi.py'.
[wsgi:error] [pid 7288:tid 1272] [client ::1:62535] Traceback (most recent call last):\r
~~中略~~
[wsgi:error] [pid 7288:tid 1272] [client ::1:62535] ModuleNotFoundError: No module named 'shibtest3'\r

⇒ WSGIモジュールが、Djangoアプリ「shibtest3」モジュールを発見できていない(らしい)。

参考:Apache2 mod_wsgi, 500 Internal Server Error

対処法

DjangoアプリへのPATHを通す。

wsgi.py
"""
WSGI config for shibtest3 project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

import os
import sys  # ←追加

from django.core.wsgi import get_wsgi_application

sys.path.append('D:/apps/shibtest3') # ←追加

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shibtest3.settings')

application = get_wsgi_application()

結果

動いた。
ss20.png

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1