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][BR]import sys

os.environ!['DJANGO_SETTINGS_MODULE'][BR][BR][BR][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][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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值