`
eonbell
  • 浏览: 59457 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Set up Brand New Django Server

阅读更多
Set up Brand New Django Server ¶

steps to set up django server (in linux):

   1. make sure set up the path of /usr/local/bin before everything

   1. install httpd (remember to set mod_rewrite) apt-get install apache2-threaded-dev

    /etc/init.d/apache2 restart

    sudo a2enmod rewrite

    ./configure --enable-rewrite

1b. have quick test on apache server

(when apache server is compile with --enable-rewrite, there would be no need to load mod_rewrite.so)

( if apache already installed without mod_rewrite, and mod_rewrite.so could not be found, use the following command:
/usr/local/apache2/bin/apxs -c -i -a [apache source]/modules/mappers/mod_rewrite.c )

   2. compile and install mod_fastcgi

cp Makefile.AP2 Makefile

make

make install

2.4 install sqlite3 (if not already there) (apt-get install sqlite3)

   3. install python (apt-get install python-dev)

3b. try import sqlite3

   4. install setup tools (apt-get install python-setuptools )

   5. install subversion (sudo apt-get install subversion)

   6. extract django project source

6b. have a quick stand alone test of the django site

6c. install optional (e.g. PIL, lxml, simplejson,flup) libraries when error is found

(

sudo apt-get install libxml2 libxml2-dev

sudo apt-get install python-imaging (install PIL)

sudo easy_install simplejson

sudo easy_install flup

)

   7. modify apache configuration for django project cgi (refer to existing httpd.conf)

(sudo apt-get install libapache2-mod-wsgi)

8.

create a file named django.wsgi in your app.

import os[[BR]]import sys

os.environ!['DJANGO_SETTINGS_MODULE'] = 'seescanlike.settings'[[BR]]sys.path.append("/app/UAT")[[BR]]sys.path.append("/app/UAT/seescanlike")

import django.core.handlers.wsgi[[BR]]application = django.core.handlers.wsgi.WSGIHandler()[[BR]]


   9. create a file in /etc/apache2/sites-avaliable , such as 001-ssl-uat. and mkdir the logs folder(/app/apache_logs/seescanlike_uat/) at first and chmod 777.

<VirtualHost *:80>
        ServerName app.sslprd.motherapp.com
        #ServerAlias 4t-cms.4tprd.motherapp.com

        RewriteEngine On

        AddOutputFilterByType DEFLATE text/html application/x-javascript text/xml

        DocumentRoot /app/UAT/seescanlike

        RewriteRule ^/(d-media)($|(\/(.*))) /app/UAT/seescanlike/$0 [L]
        RewriteRule ^/(media)($|(\/(.*))) /usr/local/lib/python2.6/site-packages/django/contrib/admin/$0 [L]
        WSGIDaemonProcess seescanlike_uat threads=25
        WSGIProcessGroup seescanlike_uat
        WSGIScriptAlias / /app/UAT/seescanlike/django.wsgi

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /app/UAT/seescanlike>
            Options FollowSymLinks MultiViews
            AllowOverride AuthConfig
            Order allow,deny
            allow from all
        </Directory>

        ErrorLog /app/apache_logs/seescanlike_uat/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /app/apache_logs/seescanlike_uat/access.log combined

</VirtualHost>





10.

cd /etc/apache2/sites-enabled/

ln -s ../sites-avaliable/001-ssl-uat 001-ssl-uat


  11. restart apache.

/etc/init.d/apache2 restart


12.

add below statemets into seetings_common.py.

otherwise ,will cause a error : IOError: sys.stdout access restricted by mod_wsgi

import sys [[BR]]sys.stdout = sys.stderr


  13. Problem "Unable to Open Database File"

    using SQLite3, your DATABASE_NAME is set to the database file's full path, the database file is writeable by Apache, but you still get the above error.

Solution

Make sure Apache can also write to the parent directory of the database. SQLite needs to be able to write to this directory.

Make sure each folder of your database file's full path does not start with number, eg. /www/4myweb/db (observed on Windows 2000).

If DATABASE_NAME is set to something like '/Users/yourname/Sites/mydjangoproject/db/db', make sure you've created the 'db' directory first.

Make sure your /tmp directory is world-writable (an unlikely cause as other thing on your system will also not work). ls /tmp -ald should produce drwxrwxrwt ...

finished.

/

run site in fast cgi (refer to renew_process), create fastcgi daemon inside ThreeCS folder:

python manage.py runfcgi method=threaded host=127.0.0.1 port=9001

   9. edit apache2 httpd.config (or /etc/apache2/extra/httpd-vhosts.conf depending on your machine)

here is an sample:

---
FastCGIExternalServer /usr/local/apache2/3HK/ThreeCS/mysite.fcgi -host 127.0.0.1:9001

<VirtualHost *:80>

  ServerName ma.three.com.hk
  DocumentRoot "/usr/local/apache2/3HK/ThreeCS"
  Alias /media /Library/Python/current/site-packages/django/contrib/admin/media
  RewriteEngine On
  RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
  RewriteRule ^(.*) /mysite.fcgi/$0 [L]
  ErrorLog "logs/error_ma_log"
  CustomLog "logs/access_ma_log" common

</VirtualHost>

Remarks 1: please make sure your DocumentRoot? and all its parent folders are accessible by the world (DocumentRoot?: chmod a+rx Parents: chmod a+x)

Remarks 2: mysite.fcgi can be a non-exist file (just for redirection)

  10. restart apache2

  12. create a fastcgi django process (renew_process)

(new) 12.5 install mod_wsgi

http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-3.3.tar.gz

  13. setup watchdog on crontab if neccessary

some hints on troubleshooting:

   1. try to run django project as stand alone server and see if it is OK

   2. try to telnet port 9001 and see if the port is opened

   3. try to use treat the django source as simple static site to check if content could be reached, and behaviour of mod_rewrite

   4. make sure the user account to run apache daemon has the right to access the web folder

  14. to install mod_header

/usr/local/apache2/bin/apxs -c -i -a [apache source]/modules/metadata/mod_headers.c

  15. in case of css problem in the admin page, add the following soft link under the following project root

media -> /Library/Python/2.6/site-packages/django/contrib/admin/media
分享到:
评论

相关推荐

    django-sslserver, Django 启用的SSL开发服务器.zip

    django-sslserver, Django 启用的SSL开发服务器 Django SSL服务器 Django SSL服务器是 Django 框架的一个已经启用SSL的开发服务器。请注意,这里不应用于生产设置。 这个应用适用于特殊的用例。 但是,大多数人应该...

    Windows server iis部署Django详细操作

    在Windows Server 2012及以上版本的服务器上部署Django Web应用,需要进行一系列的配置和安装步骤。这里重点介绍如何结合Python 3.6和IIS(Internet Information Services)来完成部署。 首先,IIS是Windows系统下...

    Python-基于PythonDjango用于restful风格API的MockServer

    Python Django框架是一个强大的Web开发平台,而将Django应用于构建MockServer,则能够帮助开发者在API实际服务未就绪之前进行前端开发或集成测试。本文将深入探讨如何利用Python Django来创建一个MockServer,以支持...

    python-django-sqlserver

    支持django使用SQL server作为数据源: DATABASES = { 'default': { 'NAME': 'my_database', 'ENGINE': 'sqlserver_ado', 'HOST': 'dbserver\\ss2008', 'USER': '', 'PASSWORD': '', } }

    learning-django.7z.002

    Caleb walks through creating a brand-new Django project, defining a data model and fields, querying the database, and using Django’s built-in URL handlers, views, and templates to structure the rest...

    django-1.6 win32扩展sqlserver 2008

    标题 "django-1.6 win32扩展sqlserver 2008" 指的是在Windows 32位环境下,使用Django 1.6框架进行开发,并且需要与SQL Server 2008数据库进行集成。描述中提到的关键需求是Python 2.7版本的运行环境、Django 1.6的...

    django3-cas-server-3.0.0.tar.gz

    标题 "django3-cas-server-3.0.0.tar.gz" 指示这是一个针对 Django 3.x 版本优化的 CAS(Central Authentication Service)服务器的源代码压缩包。CAS 是一个开源的身份验证协议,它允许用户通过单一登录(Single ...

    django-oauth2-server, 在 python 中使用 Django,OAuth2服务器写入.zip

    django-oauth2-server, 在 python 中使用 Django,OAuth2服务器写入 Django OAuth2服务器面向 Django的OAuth2服务器的。 可以以自由地对这里存储库进行 fork 。为 Django 1.9编写的:)授权类型授权代码隐式客户端...

    Django 连接sql server数据库的方法

    总之,虽然Django默认不支持SQL Server,但通过安装第三方模块以及适当配置,仍然可以实现Django项目与SQL Server数据库的集成。这不仅为Django开发者提供了更丰富的数据库选择,也为使用特定数据库产品的公司提供了...

    宝塔部署Django项目.doc

    宝塔部署 Django 项目 Django 是一个流行的 Python Web 框架,使用它可以快速开发安全、可维护的网站。宝塔是中国领先的网站管理面板,它提供了一个简洁易用的界面来管理网站。下面将详细介绍如何使用宝塔部署 ...

    django电子商务网站源码.zip

    django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django电子商务网站源码 django...

    Python库 | django-livereload-server-0.3.3.tar.gz

    **Python库 django-livereload-server-0.3.3** `django-livereload-server` 是一个基于Python的轻量级实时刷新服务器插件,专为Django框架设计。这个库的目的是为了在开发环境中提供自动刷新功能,每当项目中的静态...

    Django实现商城网站源码.zip

    Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django实现商城网站源码 Django...

    Python库 | django_cas_server-0.6.2-py2.py3-none-any.whl

    **Python库 django_cas_server-0.6.2-py2.py3-none-any.whl** 在IT领域,尤其是Web开发中,Python库扮演着至关重要的角色。`django_cas_server`是一个基于Python的中央认证服务(CAS)服务器,它允许开发者实现单点...

    Django客户管理系统源码.zip

    Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统源码 Django客户管理系统...

    django+cas环境部署

    ### django+cas环境部署知识点详解 #### 一、系统架构概述 本系统采用了Django作为主要的应用框架,并结合了Nginx、Elasticsearch、CAS(Central Authentication Service)及MySQL等多个组件来构建一个完整的分布式...

    learning-django.7z.001

    Caleb walks through creating a brand-new Django project, defining a data model and fields, querying the database, and using Django’s built-in URL handlers, views, and templates to structure the rest...

    learning-django.7z.003

    Caleb walks through creating a brand-new Django project, defining a data model and fields, querying the database, and using Django’s built-in URL handlers, views, and templates to structure the rest...

    learning-django.7z.004

    Caleb walks through creating a brand-new Django project, defining a data model and fields, querying the database, and using Django’s built-in URL handlers, views, and templates to structure the rest...

    基于Django的个人网盘源码.zip

    基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django的个人网盘源码 基于Django...

Global site tag (gtag.js) - Google Analytics