[英]Deploy django with apache2
(I am in way over my head) I am trying to deploy my django server on apache2. (我不知所措)我正在尝试在apache2上部署django服务器。 I have already buildt a quite large front-end application (that is currently deployed with apache2) and do not want to serve any views through django, rather I want to follow the backend as service principal.
我已经构建了一个很大的前端应用程序(当前已与apache2一起部署),并且不想通过django提供任何视图,而是希望将后端作为服务主体。
I have followed the instructions here: 我已按照此处的说明进行操作:
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi
After the modwsgi part I get this in my apache log file: 在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
After appending this to the apache config file: 将其附加到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>
This is the content of the wsgi file: 这是wsgi文件的内容:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PhotodiceServer.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This is the content of the urls.py file: 这是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)
This is the installed apps: 这是已安装的应用程序:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'photod',
)
previously when i entered the ip of the webserver (a raspberry pi) i was automagically routed to index.html that is stored in var/www/. 以前,当我输入Web服务器的IP(树莓派)时,我被自动路由到存储在var / www /中的index.html。
Now when i enter the ip of the webserve i get 404 page not found, do i have to explicetly say what url will load a static file somehow? 现在,当我输入Webserve的IP时,找不到404页面,我是否必须明确地说出将以某种方式加载静态文件的URL? and how will this play with the routing in angular?
这将如何与成角度的布线一起发挥作用? (I have used the angular-ui-router.js)?
(我使用了angular-ui-router.js)?
(if i set debug =False i get Bad Request (400) instead) (如果我将debug设置为False,则会收到错误请求(400))
I think you are missing a couple of things in your Apache config: 我认为您在Apache配置中缺少一些东西:
AddHandler wsgi-script .py
<Directory xxx>
Options +ExecCGI
SetHandler wsgi-script
<Directory xxx>
Options +ExecCGI
SetHandler wsgi-script
Try these, and see what it says then. 尝试这些,然后看看会说什么。
EDIT*** as your clearly not familiar with apache!! 编辑***,因为您显然不熟悉Apache !!
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
AddHandler wsgi-script .py
WSGIScriptAlias / /var/www/PhotodiceServer/PhotodiceServer/wsgi.py
WSGIPythonPath /var/www/PhotodiceServer
<Directory /var/www/PhotodiceServer/PhotodiceServer>
Options +ExecCGI
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Another EDIT*** 另一个编辑***
Here is the config I used, (although in the end I just ran uWSGI server and ProxyPass to it as it was a bit of a pain!!) 这是我使用的配置(尽管最后我只是运行了uWSGI服务器和ProxyPass,因为这有点麻烦!!)
<VirtualHost *:80>
ServerName my.local.domain
SetEnv APPLICATION_ENV development
Alias /favicon.ico /path/to/project/favicon.ico
AliasMatch ^/static/(.*)$ /path/to/project/static/$1
AddHandler wsgi-script .py
WSGIScriptAlias / /path/to/project/project/wsgi.py
WSGIDaemonProcess _WSGI user=chazmead group=www-data processes=1 threads=5 python-path=/path/to/project/venv/lib/python2.7/site-packages:/path/to/project
WSGIProcessGroup _WSGI
<Directory "/path/to/project/project/">
SetHandler wsgi-script
Options Indexes FollowSymLinks ExecCGI
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.