April 18, 2010
Django: apache でのスタティックファイルのデプロイをmod_rewriteでやる

例えば、
http://mysite.com/pr/account/profile/
で、Djangoのアカウントプロファルの処理をしてレンダリング結果を返すときに、
イメージ(*.jpg,*.gif,*.png…)とか、その他のスタティックファイル(*.css,
*.js…)は
相対パスでテンプレートに書きたいです。 URIがスラッシュで終わったらfastcgiに処理を振り分けて、拡張子付きできたら
スタティックファイルパスに
mod_rewriteすればいけそうです。

もしも、

でテンプレートに指定してあれば、http:
//mysite.com/pr/account/profile/img/header.gif がリクエストされるので、
これをhttp://mysite.com/prstatic/account/profile/img/header.gif に振り分
けるということですね。 /home/hdknr/.ve/djtweet/src/djcube/www/static/account/profile/img/header.gif
ファイルがパブリッシュされます。

# WSGI fastcgi プロセス
WSGIDaemonProcess ve_campaign user=www-data group=www-data
threads=25 
python-path=/home/hdknr/.ve/djtweet/lib/python2.5/site-packages:/home/hdknr/.ve/djtweet/bin # WSGI 仮想ディレクトリ (prアプリケーション)
WSGIScriptAlias /pr
/home/hdknr/.ve/djtweet/src/djcube/www/apache/website.wsgi

# Django Admin UI メディアファイル
Alias /pr/media
/home/hdknr/.ve/djtweet/lib/python2.5/site-packages/django/contrib/admin/media # prアプリケーションスタティクファイルのパス
Alias /prstatic /home/hdknr/.ve/djtweet/src/djcube/www/static

# WSGI アプリケーションパラメータ
WSGIReloadMechanism Process
WSGIProcessGroup ve_campaign
WSGIApplicationGroup %{SERVER}

Options All   # 拡張子付きのURLであればスタティックファイルにリライト。
RewriteEngine On
RewriteRule ^.+[txt|css|jpg|gif]$ /prstatic%{REQUEST_URI}

Posted via email from 原宿工業大学 | Comment »

March 10, 2010
PasteDeploy Application Factory for Django — twod.wsgi v1.0a2 documentation

And the following is a sample script for FastCGI:

from paste.deploy import loadapp  from flup.server.fcgi_fork import WSGIServer    app = loadapp("config:/path/to/your/config.ini")  WSGIServer(app).run()  

Sorry for making your deployment boring!

Posted via web from 原宿工業大学 | Comment »