我已经有一个Django Web应用程序正在运行,我希望通过Internet可以看到它。我甚至会考虑单独使用Django,因为它只是我想向某人展示的原型,而安全性对我来说并不是我的首要任务。但由于这看起来无法实现(或者至少我无法做到),所以我转向Apache。
问题在于有很多教程,每个教程都做不同的事情。
到目前为止,我有: - 已安装的apache(和工作) - 安装mod_wsgi(并将模块加载到Apache中) - 由于我的Django Web应用程序位于/ home / myuser / www / myapp /(或至少我存储manage.py文件的地方,因此应用程序的其余部分位于/ home / myuser / www / myapp / myapp /),我试着让apache指向那里。所以我创建了(home / 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()
BTW我还在/home/myuser/www/myapp/myapp/wsgi.py中创建新项目时自动生成wsgi Django。也许我应该使用这个,但直到现在我找到的教程都没有提到这个文件。无论如何,它的内容是:
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 webmaster@localhost
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 web,说'它有效!'。
请帮忙吗?我错过了什么?
答案 0 :(得分:8)
您是否在Apache中启用了“myapp”网站?
a2ensite myapp
因为显然你刚刚在“sites-available /”中创建了配置文件,这还不够;)
编辑:在输入上述命令之前,您可能想要禁用默认网站:
a2dissite default
希望这有帮助。
答案 1 :(得分:0)
听起来您启用了默认网站。删除/ etc / apache2 / sites-available / 000-default(或类似的东西,不记得ATM,但默认情况下)并重启apache。