zoukankan      html  css  js  c++  java
  • Django and mod_wsgi deploy example

    Django and mod_wsgi deploy example | Django foo

    Django and mod_wsgi deploy example

    Posted: January 13th, 2010 | Author: Davo | Filed under: Django | Tags: apache, Django, httpd, mod_wsgi, wsgi | No Comments »

    So what do we do next when we finished to develop(debug, debug… debug…!) our application? We go and deploy it of course!

    Well, a common choice of deploying Django application is to use Apache httpd and mod_wsgi.

    Let’s suppose the following scenario:

    • our application name is marina
    • our application is placed inside /home/ directory
    • our static files (javascript, images, css etc…) are inside /home/marina/media/

    The first step is to create the WSGI file and place it inside /home/marina/

    With the following content:

    01#!/usr/local/bin/python
    02import os, sys
    03sys.path.append('/home/')
    04sys.path.append('/home/marina/')
    05os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'  # this is your settings.py file
    06os.environ['PYTHON_EGG_CACHE'] = '/tmp'
    07 
    08import django.core.handlers.wsgi
    09 
    10application = django.core.handlers.wsgi.WSGIHandler()

    The second step is to edit your httpd.conf and add the following lines.

    01<Directory "/home/marina/media">
    02   Order deny,allow
    03   Allow from all
    04</Directory>
    05 
    06<Directory "/home/marina">
    07    AllowOverride All
    08    Order deny,allow
    09    Allow from all
    10</Directory>
    11 
    12Alias /media/ /home/marina/media/
    13ServerAdmin admin@djangofoo.com
    14ErrorLog "logs/marina.com-error_log"
    15CustomLog "logs/marina.com-access_log" common
    16# mod_wsgi configuration is here
    17# we are running as user/group 'deamon', if you don't have those you need to change or create.
    18WSGIDaemonProcess marina user=daemon group=daemon processes=2 threads=25
    19WSGIProcessGroup marina
    20# this is our WSGI file.
    21WSGIScriptAlias / /home/marina/marina.wsgi

    We need to be sure that our folder is readable by the ‘daemon‘ user

    1chown -R daemon /home/marina

    NOTE: if you are using /media/ to store all the static files be sure you have this inside your settings.py

    1ADMIN_MEDIA_PREFIX = '/admin_media/' # by default this is /media/ which conflicts with our /media/ !!

    And finally don’t forget to restart your apache.

    If you still have issues to run a Django application its worth checking the error logs.

  • 相关阅读:
    最近的一些心理活动
    object_c函数多个返回值
    nslayoutConstraint
    判断一些常用的东西
    color 的一些处理
    最近的心理活动
    加载不同的nib文件
    Be a person
    按钮居左显示
    SQLite错误码
  • 原文地址:https://www.cnblogs.com/lexus/p/2367194.html
Copyright © 2011-2022 走看看