使用mod_wsgi在Apache上部署django应用程序

时间:2023-01-19 14:33:14

I've got some problems with deploying Django application on Apache HTTP server with mod_wsgi. I've added information to httpd.conf (WSGIScriptAlias) which indicate file wsgi.py with test content:

我在使用mod_wsgi在Apache HTTP服务器上部署Django应用程序时遇到了一些问题。我已经向httpd.conf(WSGIScriptAlias)添加了信息,它指示带有测试内容的文件wsgi.py:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

and when I run it everything seems to be OK, bacause I can see 'Hello world!'. But when I change file wsgi.py to this:

当我运行它时,一切似乎都没问题,因为我可以看到'Hello world!'。但是当我将文件wsgi.py更改为:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I've got:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

wsgi.py file is in the same directory as settings.py file... (and all my app is in the subdirectory: mydomain/public_html/hc/hc/hc/settings.py - hc is the name of my app)

wsgi.py文件与settings.py文件位于同一目录中...(我的所有应用程序都在子目录中:mydomain / public_html / hc / hc / hc / settings.py - hc是我的应用程序的名称)

What can be wrong? What should I do, to make my app work? how to find out which thing causes error?

有什么不对?我该怎么办,让我的应用程序运作?如何找出导致错误的东西?

2 个解决方案

#1


1  

sys.path.append('path_to_python_dir')
sys.path.append('path_to_project')

add these lines to your wsgi.py file .

将这些行添加到您的wsgi.py文件中。

Issues in settings.py also causes 500 error.

settings.py中的问题也会导致500错误。

#2


0  

i've solve my problem on my own added this help me (after imports):

我自己解决了我的问题补充了这个帮助我(进口后):

sys.path.append('path_to_project')
sys.path.append('path_to_wsgi_py_file')

#1


1  

sys.path.append('path_to_python_dir')
sys.path.append('path_to_project')

add these lines to your wsgi.py file .

将这些行添加到您的wsgi.py文件中。

Issues in settings.py also causes 500 error.

settings.py中的问题也会导致500错误。

#2


0  

i've solve my problem on my own added this help me (after imports):

我自己解决了我的问题补充了这个帮助我(进口后):

sys.path.append('path_to_project')
sys.path.append('path_to_wsgi_py_file')