Set up Brand New Django Server

本文详细介绍在Linux环境下搭建Django服务器的步骤,包括安装配置Apache服务器、设置mod_rewrite模块、使用FastCGI及mod_wsgi部署Django应用等内容。
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
提供了基于BP(Back Propagation)神经网络结合PID(比例-积分-微分)控制策略的Simulink仿真模型。该模型旨在实现对杨艺所著论文《基于S函数的BP神经网络PID控制器及Simulink仿真》中的理论进行实践验证。在Matlab 2016b环境下开发,经过测试,确保能够正常运行,适合学习和研究神经网络在控制系统中的应用。 特点 集成BP神经网络:模型中集成了BP神经网络用于提升PID控制器的性能,使之能更好地适应复杂控制环境。 PID控制优化:利用神经网络的自学习能力,对传统的PID控制算法进行了智能调整,提高控制精度和稳定性。 S函数应用:展示了如何在Simulink中通过S函数嵌入MATLAB代码,实现BP神经网络的定制化逻辑。 兼容性说明:虽然开发于Matlab 2016b,但理论上兼容后续版本,可能会需要调整少量配置以适配不同版本的Matlab。 使用指南 环境要求:确保你的电脑上安装有Matlab 2016b或更高版本。 模型加载: 下载本仓库到本地。 在Matlab中打开.slx文件。 运行仿真: 调整模型参数前,请先熟悉各模块功能和输入输出设置。 运行整个模型,观察控制效果。 参数调整: 用户可以自由调节神经网络的层数、节点数以及PID控制器的参数,探索不同的控制性能。 学习和修改: 通过阅读模型中的注释和查阅相关文献,加深对BP神经网络与PID控制结合的理解。 如需修改S函数内的MATLAB代码,建议有一定的MATLAB编程基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值