Deployment

There are different ways to deploy Python web applications. MapProxy implements the Web Server Gateway Interface (WSGI) which is for Python what the Servlet API is for Java.

The WSGI standard allows to choose between a wide range of servers and server integration components.

MapProxy uses paster serve, a tool included as a dependency, to start these servers with a configured MapProxy application.

Paster needs a configuration where the application (MapProxy in this case) and the server is defined. The etc/ directory created with paster create (see Installation) already contains two example configurations. Both configurations define MapProxy as the WSGI application to start and setup some configuration options.

Testing

The develop.ini uses the Paster HTTP Server as the WSGI server. This server already implements HTTP so you can directly access the MapProxy with your GIS client on port 8080.

With the --reload option of paster serve MapProxy will take notice when you change any configuration and will reload these files.

This server is sufficient for local testing of the configuration. For production deployment we recommend other solutions.

Production

FastCGI is a protocol to integrate web applications into web servers. FastCGI is language-independent and implemented by most popular web servers like Apache, Lighttpd or Nginx. The applications run isolated from the web server. In this case you do not start MapProxy as an HTTP server but as a FastCGI server.

The example paster configuration config.ini does this. By default the configured server listens on a socket file (var/fcgi-socket) to which you should point your web server. But you can also use TCP/IP with the host and port option.

To start MapProxy as a FastCGI server:

paster serve etc/config.ini

Next you must configure you web server to talk to this FastCGI server.

Lighttpd

Here is an example Lighttpd configuration:

$HTTP["host"] == "example.org" {
  fastcgi.server += (
    "/proxy" => ((
      "check-local" => "disable",
      "socket"      => "/path/to/mymapproxy/var/fcgi-socket"
    ))
  )
}

The first line restricts this configuration to the example.org hostname. In the third line you set the URL path where MapProxy should listen. The socket option should point to the fcgi-socket file that is used to communicate with the MapProxy FastCGI server.

With this configuration you can access the MapProxy WMS at http://example.org/proxy/service?

Apache mod_fastcgi

You can use the following snippet to add the MapProxy FastCGI to an Apache installation:

LoadModule fastcgi_module modules/mod_fastcgi.so

<IfModule mod_fastcgi.c>
 FastCGIExternalServer /tmp/madeup -socket /path/to/mymapproxy/var/fcgi-socket
 Alias /proxy /tmp/madeup
</IfModule>

Note

/tmp/madeup is just a dummy value and you can choose any path you want, the only limitation is that the directory must exist but not the file. In this example there must be a /tmp directory but the file madeup should not exist.

nginx

The following snippet adds MapProxy to an nginx installation. Note that you need to split the URI manually if you use an nginx version before 0.7.31. If you have a more recent version, you can use fastcgi_split_path_info.

server {
  # server options
  # ...

  location /proxy {
    if ($uri ~ "^(/proxy)(/.*)$") {
      set $script_name  $1;
      set $path_info  $2;
    }
    fastcgi_pass   unix:/path/to/mymapproxy/var/fcgi-socket;
    include fastcgi_params;
    fastcgi_param  SCRIPT_NAME $script_name;
    fastcgi_param  PATH_INFO   $path_info;
  }
}

Other deployment options

Refer to http://wsgi.org/wsgi/Servers for a list of some available WSGI servers.

Note

Because of the way Python handles threads in computing heavy applications (like MapProxy WMS is), you should choose a (pre)forking-based server for best performance.

Apache mod_wsgi

If you use Apache then you can integrate MapProxy with mod_wsgi. We will not go into detail about the installation here, but you can read more about mod_wsgi installation and then loosely follow the Pylons integration instructions. Pylons is a web framework that also uses paster for WSGI application configuration and deployment, so the steps are similar.

Table Of Contents

Previous topic

Configuration examples

Next topic

Development

This Page