1

Don't know if GIS SE is the right place to ask this question. Otherwise, please feel free to suggest me where should I migrate it.

I need to access my mapfile with localhost to test my service via my intranet. At present, if I call:

http://localhost/cgi-bin/mapserver/mapserv.exe?map=C:/mapserver/umbe/mapfile/test7.map&mode=map

it works, while if I do:

http://localhost/cgi-bin/mapserver/mapserv.exe?map=http://localhost/mapserver/umbe/mapfile/test7.map&mode=map

it throws:

msLoadMap(): Unable to access file. (http://localhost/mapserver/umbe/mapfile/test7.map)

I guess it's a problem of folder/file permission, but I don't know how to solve it. I am using XAMPP, Apache web server with a Windows 10 OS. MapServer is version 7.0.4.

  • 1
    You can't make it work like that because mapfiles can't be accessed through http. – user30184 Aug 10 '17 at 15:34
  • That makes lot of sense. Anyway, how would one give access to the mapfiles in a production environment? I mean, is the client which consumes the service through (e.g.) openlayers supposed to reach the mapfile, or is mapserver on the server machine the one? In other words: What would be the URL after "map=" in a production environment? – umbe1987 Aug 10 '17 at 15:41
  • 1
    It is the Apache user who is reading the mapfiles. Clients do not have any rights for them. The map parameter will be just the same in production but usually it is hidden by configuring the http server. Read WMS documentation of MapServer and you'll find examples. – user30184 Aug 10 '17 at 15:44
  • Right, I understand now, thanks. If you like to post your comments as an answer, I'll be happy to accept it. Cheers. – umbe1987 Aug 10 '17 at 16:01
3

The map file is an internally referenced parameter, it should only be referenced using a file path, not a URL.

On Apache, you can use SetEnvIf to remove it from your URL, something like:

SetEnvIf Request_URI "/cgi-bin/mapserver/mapserv.exe"  MS_map file=C:/mapserver/umbe/mapfile/test7.map
1

The concept of mapfile is not very well described in MapServer documentation http://www.mapserver.org/mapfile/index.html. However, MapServer is a cgi-bin program. If you run MapServer with Apache http server it is the Apache user, typically "www-data", see https://www.cyberciti.biz/faq/unix-osx-linux-find-apache-user/ who is accessing the mapfiles. Clients can send a request with &map= parameter that tells mapserver-cgi what mapfile to use.

The Apache user must have rights for reading the mapfiles but the clients of MapServer do not need to have any access to mapfiles and they should never have it. Consider a mapfile that has PostGIS layers http://www.mapserver.org/input/vector/postgis.html. If users could read the mapfile they would get also username/password of the database. So do not ever store mapfiles to the document root directory of your http server where users could access them with their browsers or other http client!

It is known to be ugly to include a path to the mapfile in the server URL and therefore there is an own chapter in the MapServer WMS documentation about some alternative ways for hiding it http://mapserver.org/ogc/wms_server.html#changing-the-online-resource-url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.