我正在尝试部署我的第一个Django应用程序(在A2 Hosting上)。不幸的是,我无法访问我的Apache2 conf文件(和/或httpd),我只能修改.htaccess文件,而不是你在下面看到的。 经过多次尝试,我认为是Apache服务器无法加载wsgi.py,因为我添加了一个日志文件,在调用wsgi.py文件时创建并且它没有创建(我尝试手动和日志文件已正确创建。)
现在,我正在努力打印Django“Wello World”,因为我想,如果我不能通过这个基本步骤,我该如何部署我的“真实”应用程序...... 最后,我在虚拟环境中运行Django 1.11.6和Python 3.5.4。
的.htaccess
DirectoryIndex /home/hairduseres/public_html/myapp/myapp/myapp/wsgi.py
WSGIScriptAlias / /home/user/public_html/myapp/myapp/myapp/wsgi.py
WSGIPythonHome /home/user/virtualenv/myapp/3.5
WSGIPythonPath /home/user/public_html/myapp
<Directory /home/user/public_html/myapp/myapp/myapp/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/public_html/myapp"
PassengerBaseURI "/myapp"
PassengerPython "/home/user/virtualenv/myapp/3.5/bin/python3.5"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
wsgi.py
"""
WSGI config for myapp 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/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
print('===== sys.path / PYTHONPATH =====')
for k in sorted(os.environ.keys()):
v = os.environ[k]
print ('%-30s %s' % (k,v[:70]))
print(os.environ['VIRTUAL_ENV'])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
logs = open("/home/user/logs", 'a')
logs.write("(wsgi.py) file correctly load \n")
logs.close()
application = get_wsgi_application()
我已经看过了: Django AND .htaccess rewrites/redirects, is this possible?,Configure WSGI with Django on OpenShift 当然,在Django网站以及许多其他网站上,不幸的是他们解释了当用户访问Apache conf文件时如何部署Django应用程序...
答案 0 :(得分:2)
您不能使用WSGIScriptAlias
或您尝试在.htaccess
文件中使用的其他mod_wsgi指令。如果您对Apache httpd服务器本身没有任何控制权,那么您就不太可能使用mod_wsgi。