我有我的apache服务器将流量从mysite.com/home
引到wsgi.py文件,但是当调用get_wsgi_application()
时出现内部服务器错误。
在Amazon Linux EC2上运行apache2。在wsgi.py中,我替换了
application = get_wsgi_application()
具有功能
def application(environ, start_response):
status = '200 OK'
output = b'sys.path = %s\n' % repr(sys.path).encode('UTF-8')
output += b'sys.version = %s\n' % repr(sys.version).encode('UTF-8')
output += b'sys.prefix = %s\n' % repr(sys.prefix).encode('UTF-8')
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
,服务器错误消失。它表明apache使用的是正确的python版本(3.7),当我从import get_wsgi_application()
django.core.wsgi
import os, sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
sys.path.append('/usr/local/wsgi/django')
sys.path.append('/usr/local/wsgi/django/mysite')
application = get_wsgi_application()
时不返回错误。据我了解,这意味着apache可以很好地找到我的django项目的访问点,并且它有权查看文件并显示其内容。我想念什么?
我能想到的其他可能相关的信息: 用户“ apache”和组“ apache”拥有外部mysite目录及其中的所有内容。我已经根据Django部署清单在settings.py中为生产设置了所有设置。 https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
wsgi.py:
<VirtualHost *:80>
ServerName www.mysite.com
Redirect permanent / httpswww.mysite.com
</VirtualHost>
<VirtualHost *:443>
ServerName httpswww.mysite.com
ServerAlias mysite.com
ServerAdmin person@gmail.com
DocumentRoot "/var/www/html/efs/Website"
WSGIDaemonProcess mysite
WSGIProcessGroup mysite
WSGIScriptAlias /home /usr/local/wsgi/django/mysite/mysite/wsgi.py
<Directory "/usr/local/wsgi/django/mysite/mysite">
<Files "wsgi.py">
Require all granted
</Files>
</Directory>
SSLEngine on
SSLCertificateFile "/crt/path.crt"
SSLCertificateKeyFile "/key/path.key"
</VirtualHost>
httpd.conf:
SECRET_KEY = 'string_I_havent_moved_yet'
DEBUG= False
ALLOWED_HOSTS = ['www.mysite.com', e2-serial-numbers.compute-1.amazonaws.com']
settings.py:
{{1}}