如何将MapServer设置为通过HTTPS访问服务的客户端

修订

$版次:12521$

日期

$日期:2011-09-06 19:48:20+0200(周二,2011年9月6日)$

介绍

以下文档解释了如何将MapServer设置为客户端,以便使用HTTPS协议通过安全的SSL连接访问WMS/WFS服务器。它描述了用户可能遇到的常见问题以及如何解决这些问题。

要求

mapserver 5.4.1及更高版本,使用curl编译。curl必须使用SSL支持构建。

默认安装(使用apt-get-install、rpm、manual等)

curl ca bundle文件应位于默认目录中。

验证您与curl命令行的连接:

curl https://targethostname:port/gmap-demo/gmap75.phtml

编辑 Mapfile 以添加WMS连接URL。例如:

CONNECTION "https://domainname:port/cgi-bin/mapserv?map=/path/to/wms.map"
CONNECTIONTYPE WMS

如果图层显示正确,则无需继续阅读。

非标准安装(与MS4W和FGS共用)

如果出现以下错误,则表示找不到CA包。

curl https://localhost:port/gmap-demo/gmap75.phtml
curl: (77) error setting certificate verify locations:
  CAfile: /home/nsavard/fgsfull/share/curl/cacert.pem
  CApath: none

这可能是由于curl_ca_bundle环境变量指向错误的位置或ca bundle文件不存在造成的。按照以下步骤纠正任何情况。

将curl_ca_bundle环境变量设置为指向bundle文件(例如export curl_ca_bundle=/path/to/my-ca-bundle.ext,其中my-ca-bundle.ext可以是cacert.pem或ca bundle.crt)。

下载在http://curl.haxx.se/docs/caextract.html上找到的ca bundle文件“cacert.pem”,或者如果您有curl源,可以通过执行“make ca bundle”或“make ca firefox”(如果您安装了firefox和certutil工具)来创建ca bundle。如果使用第二个选项,包文件将命名为ca-bundle.crt,并将在curl根目录下的lib目录中找到。有关详细信息,请参阅http://curl.haxx.se/docs/caextract.html。将此文件存储在url_ca_bundle环境变量指向的位置。

使用curl命令行验证连接:

curl https://targethostname:port/gmap-demo/gmap75.phtml

注解

如果您使用MS4W、OSGEO4W或FGS安装,这些安装程序应该为您解决这个问题。

具有自签名SSL证书的远程服务器

如果出现以下错误,则意味着您的远程服务器可能使用自签名的SSL证书,并且服务器证书不包含在您的CA包文件中。

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

要获取远程服务器证书,必须执行以下命令:

openssl s_client -connect domainname:port

将所有内容从“--begin certificate-----”标记复制到“--end certificate-----”标记。将其粘贴到my-ca-bundle.ext文件的末尾。

验证您与curl命令行的连接:

curl https://targethostname:port/gmap-demo/gmap75.phtml

注解

如果出现以下错误,则表示URL请求中的域名与创建远程服务器证书时声明的域名不对应。

curl: (51) SSL: certificate subject name 'domainname' does not match target host name 'domainname'

您必须使用与生成远程服务器证书时使用的“公用名”提示中显示的域名完全相同的域名。例如,不能使用远程服务器IP。这意味着以下URL是不可接受的。

CONNECTION "https://xxx.xxx.xxx.xxx:port/cgi-bin/mapserv?map=/path/to/wms.map"
CONNECTIONTYPE WMS