environment
.htaccess
- .py の CGI 設定
- URL のハンドル
- HTTP_AUTHORIZATION を環境変数に追加
AddHandler cgi-script .py
RewriteEngine on
RewriteBase /hoge/
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule .* index.py
index.py
- shebang を設定
- 改行コードは LF
- CGI として動くように mod
- テンプレートで組み込み変数すら使うなと怒るので調教
import __builtin__
import os
import web
web.template.global_globals.update(__builtin__.__dict__)
web.template.global_globals['web'] = web
env = os.environ
if 'SERVER_SOFTWARE' in env and 'GATEWAY_INTERFACE' in env:
def runwsgi(func):
dirname = os.path.dirname(env['SCRIPT_NAME'])
env['SCRIPT_NAME'] = dirname
env['PATH_INFO'] = env['REQUEST_URI'][len(dirname):]
import flup.server.cgi as flups
return flups.WSGIServer(func).run()
web.wsgi.runwsgi = runwsgi
参考
BASIC認証メモ
CGI環境でweb.pyを動かす