【发布时间】:2014-05-20 10:32:59
【问题描述】:
(我有点不知所措)我正在尝试在 apache2 上部署我的 django 服务器。我已经构建了一个相当大的前端应用程序(当前使用 apache2 部署)并且不想通过 django 提供任何视图,而是希望将后端作为服务主体。
我已按照此处的说明进行操作:
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi
在 modwsgi 部分之后,我在我的 apache 日志文件中得到了这个:
[Tue May 20 12:19:44 2014] [notice] Apache/2.2.22 (Debian) PHP/5.4.4-14+deb7u8 mod_wsgi/3.4 Python/2.7.3 configured -- resuming normal operations
将其附加到 apache 配置文件后:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIScriptAlias / /var/www/PhotodiceServer/PhotodiceServer/wsgi.py
WSGIPythonPath /var/www/PhotodiceServer
<Directory /var/www/PhotodiceServer/PhotodiceServer>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
这是wsgi文件的内容:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PhotodiceServer.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
这是 urls.py 文件的内容:
from django.conf.urls import patterns, include, url
from django.contrib.auth.models import User, Group
from rest_framework import viewsets, routers
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browseable API.
url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
)
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
model = User
class GroupViewSet(viewsets.ModelViewSet):
model = Group
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
这是已安装的应用程序:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'photod',
)
之前,当我输入网络服务器(树莓派)的 ip 时,我会自动路由到存储在 var/www/ 中的 index.html。
现在,当我输入 webserve 的 ip 时,找不到 404 页面,我是否必须明确说明什么 url 会以某种方式加载静态文件?以及这将如何与角度路由一起使用? (我用过angular-ui-router.js)?
(如果我设置 debug =False 我会得到 Bad Request (400))
【问题讨论】:
-
几个问题:您为什么使用过时的指南(该页面顶部有一个红色警告,请尝试使用实际安装的指南:docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi)。另一个是:为什么是 Apache?有更好的替代品,例如 Nginx(更好的性能、安全性等)。此外,发布您的实际配置可能会很有帮助,而不仅仅是指向您遵循的指南的链接。这意味着:您的 Apache .conf 文件,您安装该 Django 应用程序的方式/位置。
-
谢谢,我在更改为其他指南后编辑了帖子。为什么是阿帕奇?让我们说我的名字是约翰·斯诺(我什么都不知道)。我已经在我的 var/www 指令中安装了 django 应用程序...使用我认为的 starproject 命令...我已经尝试配置了一段时间不记得确切
-
Internal Server Error表示您的应用配置存在一些错误。你能把你wsgi.py的内容放在这里吗?还可以尝试将DEBUG=True放在应用程序的设置中,这样任何请求都会显示错误回溯而不是简洁的错误消息。您也可以尝试在该服务器上运行manage.py runserver(可以吗,对吗?)并在该服务器上的某些基于控制台的浏览器中显示该页面(链接)或将其存储在html文件wget(wget http://localhost:8000)中跨度> -
看起来您想要做的是使用 django 作为 Angular 的 REST 后端。阅读this tutorial,它会向您展示如何做到这一点。 what are the best practices to use AngularJS with django 问题也很有用;最后
django-angular也刚刚发布。 -
我删除了angularjs 标签,因为这个问题不是关于角度的,而是使用 mod_wsgi 设置 django。碰巧您正在使用 angular 作为 django 应用程序的前端,但这与此无关;您还在一篇文章中提出了多个问题。请将帖子限制在一个(可回答的)问题上。