agangliu0400 发表于 2018-12-9 12:13:04

OpenLayers基础:在IIS中部署并启用CGI

  在使用OpenLayers过程中,若在IIS下部署,需要在IIS启用CGI,当前以IIS7为例进行介绍如何来启用CGI和相关的设置。启用CGI的目的是使用WFS的前提,因为WFS在请求过程中会出现跨域问题,所以根据OpenLayers的建议,只需要使用其自带的代理CGI。
  1. 安装python
  由于OpenLayers下的默认内置CGI是python实现的,所有要在机器上预先安装python运行环境,关于其安装,本文也不过多介绍,可以去官网http://www.python.org上下载安装即可。
  2. 启用CGI
关于如下在IIS7中启用CGI,请参考本人前面的博文《在IIS7中启用CGI》,里面已做详细介绍,在此不做赘述,最终设置如下图。
http://blog.运维网.com/attachment/201107/132724604.png
  3. 添加代理域
  打开OpenLayers下的proxy.cgi,前部分代码如下:


[*]#!/usr/bin/env python
[*]
[*]"""This is a blind proxy that we use to get around browser
[*]restrictions that prevent the Javascript from loading pages not on the
[*]same server as the Javascript.This has several problems: it's less
[*]efficient, it might break some sites, and it's a security risk because
[*]people can use this proxy to browse the web and possibly do bad stuff
[*]with it.It only loads pages via http and https, but it can load any
[*]content type. It supports GET and POST requests."""
[*]
[*]import urllib2
[*]import cgi
[*]import sys, os
[*]
[*]# Designed to prevent Open Proxy type stuff.
[*]
[*]allowedHosts = ['www.openlayers.org', 'openlayers.org',
[*]                '192.168.0.201:8088',
[*]                'labs.metacarta.com', 'world.freemap.in',
[*]                'prototype.openmnnd.org', 'geo.openplans.org',
[*]                'sigma.openplans.org', 'demo.opengeo.org',
[*]                'www.openstreetmap.org', 'sample.avencia.com']
[*]
[*]method = os.environ["REQUEST_METHOD"]
[*]# ...

  python变量allowedHosts中,默认已添加了openlayers相关的网站域名,在实际应用过程中,本人的GeoServer的IP为192.168.0.201:8088,将其添加到其中即可。
  4. 指定代理地址
  在openlayers在使用wfs时,只需要添加如下一行代码即可,proxy.cgi的路径可以跟据实际情况来指定,由于本人实际应用中,是将proxy.cgi放在当前程序的相同目录。


[*]OpenLayers.ProxyHost = "proxy.cgi?url=";

  P.S. 设置比较简单,持续应用中。



页: [1]
查看完整版本: OpenLayers基础:在IIS中部署并启用CGI