Django应用程序托管在Ubuntu VM与Apache和mod_wsgi不显示 [英] Django application hosted on Ubuntu VM with Apache and mod_wsgi not showing up
问题描述
我已经上传了我的第一个Django应用程序,但是我无法访问它。该应用程序称为调查,并已上传到运行 Apache
的 Ubunto VM
code> mod_wsgi的。我的虚拟机已通过 http://phaedrus.scss.tcd.ie/bias_experiment使用代理通行证公开
I have uploaded my first Django Application but I am having trouble accessing it. The application is called survey and has been uploaded onto an Ubunto VM
running Apache
with mod_wsgi
. My VM has been made public using a Proxy pass at http://phaedrus.scss.tcd.ie/bias_experiment
根据以下 urls.py
文件,调查应在 http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ 当我在本地访问它工作在 http://127.0.0.1:8000/surveythree/
Per the urls.py
file below, the survey should be available at http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ When I access it locally it works at http://127.0.0.1:8000/surveythree/
我已经发布了两个相关问题< a href =https://stackoverflow.com/questions/24209181/what-should-be-the-url-of-my-django-application>(1) (2),并在相关问题上获得了很多帮助。但是应用程序仍然不可见,我不明白为什么。
I have posted two questions related (1)(2) to this lately and have received lots of help on related issues. However the application is still not visible and I do not understand why.
我采取的步骤
- 项目到/ var / www /(项目结构如下)
- 已安装virtualenv
- 已安装mod_wsgi
- 安装任何其他相关软件包
- 创建虚拟主机文件(下)
- 创建了index.wsgi文件(下)
- 重新启动的apache
- Ran a2ensite
a2ensite bias_experiment
- 重新启动的apache
- Uploaded the project to /var/www/ (project structure is below)
- Installed virtualenv
- Installed mod_wsgi
- Installed any other related packages
- Created the virtualhost file (below)
- Created the index.wsgi file (below)
- Restarted apache
- Ran a2ensite
a2ensite bias_experiment
- Restarted apache
但是当用户访问 http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ 他们会得到一个Apache 404错误页面,访问 http://phaedrus.scss.tcd.ie/bias_experiment/ 将向他们显示文件系统,
However when the user visited http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ they would get an Apache 404 error page and visiting http://phaedrus.scss.tcd.ie/bias_experiment/ would show them the file system,
然后,我添加了一个直接链接到wsgi文件e $ / etc / apache2 / sites-available / default
I then added a direct link to the wsgi file by adding the below to /etc/apache2/sites-available/default
WSGIScriptAlias /bias_experiment/ /var/www/bias_experiment/src/bias_experiment/index.wsgi
现在当用户访问 http://phaedrus.scss.tcd.ie/bias_experiment/ 他们至少看到Django正在运行。但请访问 http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/仍然导致Apache 404错误页面。
Now when the user visits http://phaedrus.scss.tcd.ie/bias_experiment/ they at least see Django is running. However visiting http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ still results in an Apache 404 error page.
任何人都可以看到我的设置有什么问题?我已经遵循了多个教程,并广泛地研究了这一点,但无法理解。
Can anyone see what is wrong with my setup? I have followed multiple tutorials and extensively looked into this but cannot figure it out.
以下是我的设置请随时要求任何有条件的细节。
The below is my setup Please feel free to request any aditional details.
感谢
我的VirtualHost文件位于 / etc / apache2 / sites-可用/ bias_experiment
My VirtualHost file located at /etc/apache2/sites-available/bias_experiment
<VirtualHost *:80>
ServerAdmin myemail@gmail.com
ServerName phaedrus.scss.tcd.ie/bias_experiment
ServerAlias phaedrus.scss.tcd.ie
WSGIScriptAlias /bias_experiment/ /var/www/bias_experiment/src/bias_experiment/index.wsgi
Alias /static/ /var/www/bias_experiment/src/bias_experiment/static/
<Location "/static/">
Options -Indexes
</Location>
</VirtualHost>
我的index.wsgi文件位于 / var / www / bias_experiment / src / bias_experiment / index.wsgi
My index.wsgi file located at /var/www/bias_experiment/src/bias_experiment/index.wsgi
import os
import sys
import site
# This was kept in order to add the src folder
sys.path.append('/var/www/bias_experiment/src')
sys.path.append('/var/www/bias_experiment/src/bias_experiment')
os.environ['DJANGO_SETTINGS_MODULE'] = 'bias_experiment.settings'
# Activate your virtual env
activate_env=os.path.expanduser("/var/www/bias_experiment/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我的urls.py文件位于 /var/www/bias_experiment/src/bias_experiment/urls.py
My urls.py file located at /var/www/bias_experiment/src/bias_experiment/urls.py
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),
)
我的Apace错误日志 tail /var/log/apache2/error.log
(bias_experiment)spillab@kdeg-vm-18:/var/www/bias_experiment$ sudo tail /var/log/apache2/error.log
[Sun Jun 15 17:37:26 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
[Sun Jun 15 17:37:50 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
[Sun Jun 15 18:38:11 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
[Sun Jun 15 18:39:53 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
[Sun Jun 15 18:40:00 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
[Sun Jun 15 18:40:01 2014] [error] [client 134.226.38.233] Target WSGI script not found or unable to stat: /var/www/bias_experiment/src/bias_experiment/index.wsgisurveythree
(bias_experiment)spillab@kdeg-vm-18:/var/www/bias_experiment$
我的项目结构
谢谢!
推荐答案
我认为虚拟主机是不启动,因为您使用的服务器名称是该服务器的主要名称。所以我们可以完全删除,我们需要专注于 / sites-available / default
中的内容。我认为唯一错误的是我们不需要别名中的斜线:
I think the virtual host is a non-starter, because the server name you are using is the main name of that server. So we can probably delete that altogether, and we need to concentrate on what's in /sites-available/default
. And I think the only thing wrong there is that we don't need a trailing slash in the alias:
WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi
(我以前可能会双向引导你错误的是,但这次我在mod_wsgi文档中直接从作者Graham Dumpleton发现了这个建议。)
(I might have previously steered you doubly wrong on that, but this time I found the recommendation in the mod_wsgi documentation directly from the author, Graham Dumpleton.)
这篇关于Django应用程序托管在Ubuntu VM与Apache和mod_wsgi不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!