我已经有了一个Django Web应用程序可以工作,并且我想让它通过Internet可见。我甚至会考虑单独使用Django,因为它只是我想要展示给某人的原型,而安全对我来说现在不是优先考虑的事情。但是由于这看起来不可能实现(或者至少我没能做到),我正在转向Apache。使用Apache部署Django
问题是,有很多教程,每个人都做不同的事情。
到现在为止,我有: - 安装了Apache(和作品) - 安装mod_wsgi的(和模块加载到Apache)的 - 因为我的Django的web应用程序是在/ home/myuser的/ WWW/MYAPP /(或至少这是我存储manage.py文件的地方,其余的应用程序位于/ home/myuser/www/myapp/myapp /),我试图在那里创建Apache。因此,我创建(住宅/ myuser的/ WWW/MYAPP /的apache.conf/web.wsgi具有以下内容:
import os, sys
sys.path.append('/home/myuser/www/myapp/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
顺便说一句我也有WSGI Django的创建一个新项目时自动生成的/ home/myuser的。/www/myapp/myapp/wsgi.py也许我应该用这一个,但没有我发现到现在的教程确实提到这个文件的任何方式,其内容是:
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from myapp.wsgi import MyAppApplication
# application = MyAppApplication(application)
最后,我使用默认的模板创建/ etc/apache2/sites-available/myapp文件,如下所示:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /home/myuser/www/myapp/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher | .py
PythonDebug On
</Directory>
<Directory /home/myuser/www/myapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/myuser/www/myapp/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/myuser/www/myapp/access.log combined
</VirtualHost>
尽管我描述了自己的努力,但当我导航到localhost时,我只能看到默认的apache网页,并说'It works!'。
请帮忙吗?我错过了什么?