apache+python+tilecache配置(一)

1.安装 httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
2.安装 python-2.5.msi
3.安装 mod_python-3.3.1.win32-py2.5-Apache2.2.exe
4.配置httpd.conf
第一步 加载mod_python
LoadModule python_module modules/mod_python.so

第二步 添加处理程序.在mime_module中加入
    AddHandler cgi-script .cgi .pl
    AddHandler mod_python .py
Include conf/extra/httpd-vhosts.conf
第三步 配置#TileCache虚拟目录,AddHandler部分如果配了在第二部可以省掉
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName dummy-host.test.cn
    ServerAlias www.dummy-host.test.cn
    ErrorLog "logs/dummy-host.test.cn-error.log"
    CustomLog "logs/dummy-host.test.cn-access.log" common
    DocumentRoot "D:/server/tilecache-2.11"
    <Directory "D:/server/tilecache-2.11/">
        AddHandler mod_python .py
        AddHandler python-program .py
        PythonHandler TileCache.Service
        PythonOption TileCacheConfig D:/server/tilecache-2.11/tilecache.cfg
        PythonDebug On
        PythonPath "['D:/server/tilecache-2.11/']+sys.path"
        AllowOverride None
        Options Indexes FollowSymLinks Multiviews 
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

第14行很重要pythonPath如果没配好运行时碰到错误
引用
ImportError: No module named TileCache.Service
解决办法在"运行",输入"Regedit",打开注册表编辑器,在注册表的
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.5\PythonPath]
位置下的键值中添加TileCache的位置"D:\server\tilecache-2.11\"

第四步 配置TileCache的tilecache.cgi将第一行更改如下,保存后,将扩展名改成.py,配置好缓存
#!D:/dev/Python25/python.exe -u

[cache]
type=Disk
base=E:/TileCache

查看单片
查看全图
由于在TileCache的源码中还是默认调用了cgi的接口,这里为了彻底摆脱cgi,可以将TileCache目录下的tilecache.py修改为
import urllib2
from TileCache import Service, cgiHandler, cfgfiles, handler

if __name__ == '__main__':
# svc = Service.load(*cfgfiles)
# cgiHandler(svc)
  handler(urllib2.Request)

同样service.py也修改为

if __name__ == '__main__':
# svc = Service.load(*cfgfiles)
# cgiHandler(svc)
  handler(urllib2.Request)

猜你喜欢

转载自xml.iteye.com/blog/1724875