简体   繁体   中英

Deploy django with apache2

(I am in way over my head) I am trying to deploy my django server on apache2. 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.

I have followed the instructions here:

https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/modwsgi

After the modwsgi part I get this in my apache log file:

  [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:

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:

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:

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/.

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? and how will this play with the routing in angular? (I have used the angular-ui-router.js)?

(if i set debug =False i get Bad Request (400) instead)

I think you are missing a couple of things in your Apache config:

  1. AddHandler wsgi-script .py
  2. In <Directory xxx> Options +ExecCGI SetHandler wsgi-script

Try these, and see what it says then.

EDIT*** as your clearly not familiar with 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!!)

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM