This file is indexed.

/usr/share/doc/mapproxy/html/deployment.html is in mapproxy-doc 1.9.0-3+deb9u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Deployment &#8212; MapProxy 1.8.2a0 Docs</title>
    
    <link rel="stylesheet" href="_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-3.3.6/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-3.3.6/css/bootstrap-theme.min.css" type="text/css" />
    <link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
    <link rel="stylesheet" href="_static/mapproxy.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.8.2a0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="_static/js/jquery-fix.js"></script>
    <script type="text/javascript" src="_static/bootstrap-3.3.6/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="_static/bootstrap-sphinx.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="MapProxy 1.8.2a0 Docs" href="index.html" />
    <link rel="next" title="Configuration examples" href="configuration_examples.html" />
    <link rel="prev" title="mapproxy-util autoconfig" href="mapproxy_util_autoconfig.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">

  </head>
  <body role="document">

<div id="navbar" class="navbar navbar-default ">
  <div class="container">
    <div class="navbar-header">
      <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="index.html" class="pull-left"><img src="_static/logo.png" height="50">
      </a>
      <a class="navbar-brand" href="index.html">
        <span>
          MapProxy</span>
        <span>1.8.2a0</span>
      </a>
    </div>
    <div class="collapse navbar-collapse nav-collapse">
      
        
<form class="navbar-form navbar-right" action="search.html" method="get">
 <div class="form-group">
  <input type="text" name="q" class="form-control" placeholder="Search" />
 </div>
  <input type="hidden" name="check_keywords" value="yes" />
  <input type="hidden" name="area" value="default" />
</form>
      
    </div>
  </div>
</div>

<div class="container">
  <div class="row">
      <div class="col-md-3">
        <div id="sidebar" class="bs-sidenav" role="complementary"><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="install_windows.html">Installation on Windows</a></li>
<li class="toctree-l1"><a class="reference internal" href="install_osgeo4w.html">Installation on OSGeo4W</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="configuration.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="services.html">Services</a></li>
<li class="toctree-l1"><a class="reference internal" href="sources.html">Sources</a></li>
<li class="toctree-l1"><a class="reference internal" href="caches.html">Caches</a></li>
<li class="toctree-l1"><a class="reference internal" href="seed.html">Seeding</a></li>
<li class="toctree-l1"><a class="reference internal" href="coverages.html">Coverages</a></li>
<li class="toctree-l1"><a class="reference internal" href="mapproxy_util.html">mapproxy-util</a></li>
<li class="toctree-l1"><a class="reference internal" href="mapproxy_util_autoconfig.html">mapproxy-util autoconfig</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Deployment</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#testing">Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="#production">Production</a></li>
<li class="toctree-l2"><a class="reference internal" href="#apache-mod-wsgi">Apache mod_wsgi</a></li>
<li class="toctree-l2"><a class="reference internal" href="#behind-http-server-or-proxy">Behind HTTP server or proxy</a></li>
<li class="toctree-l2"><a class="reference internal" href="#other-deployment-options">Other deployment options</a></li>
<li class="toctree-l2"><a class="reference internal" href="#performance">Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="#load-balancing-and-high-availablity">Load Balancing and High Availablity</a></li>
<li class="toctree-l2"><a class="reference internal" href="#logging">Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="#multimapproxy">MultiMapProxy</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="configuration_examples.html">Configuration examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="inspire.html">INSPIRE View Service</a></li>
<li class="toctree-l1"><a class="reference internal" href="labeling.html">WMS Labeling</a></li>
<li class="toctree-l1"><a class="reference internal" href="auth.html">Authentication and Authorization</a></li>
<li class="toctree-l1"><a class="reference internal" href="decorate_img.html">Decorate Image</a></li>
<li class="toctree-l1"><a class="reference internal" href="development.html">Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="mapproxy_2.html">MapProxy 2.0</a></li>
</ul>

        </div>
      </div>
    <div class="col-md-8">
      
  <div class="section" id="deployment">
<h1>Deployment<a class="headerlink" href="#deployment" title="Permalink to this headline"></a></h1>
<p>MapProxy implements the Web Server Gateway Interface (WSGI) which is for Python what the Servlet API is for Java. There are different ways to deploy WSGI web applications.</p>
<p>MapProxy comes with a simple HTTP server that is easy to start and sufficient for local testing, see <a class="reference internal" href="#deployment-testing"><span class="std std-ref">Testing</span></a>. For production and load testing it is recommended to choose one of the <a class="reference internal" href="#deployment-production"><span class="std std-ref">production setups</span></a>.</p>
<div class="section" id="testing">
<span id="deployment-testing"></span><h2>Testing<a class="headerlink" href="#testing" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">serve-develop</span></code> subcommand of <code class="docutils literal"><span class="pre">mapproxy-util</span></code> starts an HTTP server for local testing. It takes an existing MapProxy configuration file as an argument:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">mapproxy</span><span class="o">-</span><span class="n">util</span> <span class="n">serve</span><span class="o">-</span><span class="n">develop</span> <span class="n">mapproxy</span><span class="o">.</span><span class="n">yaml</span>
</pre></div>
</div>
<p>The server automatically reloads if the configuration or any code of MapProxy changes.</p>
<dl class="cmdoption">
<dt id="cmdoption-mapproxy-util-serve-develop--bind">
<span id="cmdoption-mapproxy-util-serve-develop-b"></span><code class="descname">--bind</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">-b</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-mapproxy-util-serve-develop--bind" title="Permalink to this definition"></a></dt>
<dd><p>Set the socket MapProxy should listen. Defaults to <code class="docutils literal"><span class="pre">localhost:8080</span></code>.
Accepts either a port number or <code class="docutils literal"><span class="pre">hostname:portnumber</span></code>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-mapproxy-util-serve-develop--debug">
<code class="descname">--debug</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-mapproxy-util-serve-develop--debug" title="Permalink to this definition"></a></dt>
<dd><p>Start MapProxy in debug mode. If you have installed <a class="reference external" href="http://pypi.python.org/pypi/Werkzeug">Werkzeug</a> (recommended) or <a class="reference external" href="http://pypi.python.org/pypi/Paste">Paste</a>, you will get an interactive traceback in the web browser on any unhandled exception (internal error).</p>
</dd></dl>

<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This server is sufficient for local testing of the configuration, but it is <cite>not</cite> stable for production or load testing.</p>
</div>
<p>The <code class="docutils literal"><span class="pre">serve-multiapp-develop</span></code> subcommand of <code class="docutils literal"><span class="pre">mapproxy-util</span></code> works similar to <code class="docutils literal"><span class="pre">serve-develop</span></code> but takes a directory of MapProxy configurations. See <a class="reference internal" href="#multimapproxy"><span class="std std-ref">MultiMapProxy</span></a>.</p>
</div>
<div class="section" id="production">
<span id="deployment-production"></span><h2>Production<a class="headerlink" href="#production" title="Permalink to this headline"></a></h2>
<p>There are two common ways to deploy MapProxy in production.</p>
<dl class="docutils">
<dt>Embedded in HTTP server</dt>
<dd>You can directly integrate MapProxy into your web server. Apache can integrate Python web services with the <code class="docutils literal"><span class="pre">mod_wsgi</span></code> extension for example.</dd>
<dt>Behind an HTTP server or proxy</dt>
<dd>You can run MapProxy as a separate local HTTP server behind an existing web server (<a class="reference external" href="http://nginx.org">nginx</a>, Apache, etc.) or an HTTP proxy (<a class="reference external" href="http://www.varnish-cache.org/">Varnish</a>, squid, etc).</dd>
</dl>
<p>Both approaches require a configuration that maps your MapProxy configuration with the MapProxy application. You can write a small script file for that.</p>
<p>Running MapProxy as a FastCGI server behind HTTP server, a third option, is no longer advised for new setups since the FastCGI package (flup) is no longer maintained and the Python HTTP server improved significantly.</p>
<div class="section" id="server-script">
<span id="id1"></span><h3>Server script<a class="headerlink" href="#server-script" title="Permalink to this headline"></a></h3>
<p>You need a script that makes the configured MapProxy available for the Python WSGI servers.</p>
<p>You can create a basic script with <code class="docutils literal"><span class="pre">mapproxy-util</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">mapproxy</span><span class="o">-</span><span class="n">util</span> <span class="n">create</span> <span class="o">-</span><span class="n">t</span> <span class="n">wsgi</span><span class="o">-</span><span class="n">app</span> <span class="o">-</span><span class="n">f</span> <span class="n">mapproxy</span><span class="o">.</span><span class="n">yaml</span> <span class="n">config</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>The script contains the following lines and makes the configured MapProxy available as <code class="docutils literal"><span class="pre">application</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mapproxy.wsgiapp</span> <span class="k">import</span> <span class="n">make_wsgi_app</span>
<span class="n">application</span> <span class="o">=</span> <span class="n">make_wsgi_app</span><span class="p">(</span><span class="s1">&#39;examples/minimal/etc/mapproxy.yaml&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>This is sufficient for embedding MapProxy with <code class="docutils literal"><span class="pre">mod_wsgi</span></code> or for starting it with Python HTTP servers like <code class="docutils literal"><span class="pre">gunicorn</span></code> (see further below). You can extend this script to setup logging or to set environment variables.</p>
<p>You can enable MapProxy to automatically reload the configuration if it changes:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mapproxy.wsgiapp</span> <span class="k">import</span> <span class="n">make_wsgi_app</span>
<span class="n">application</span> <span class="o">=</span> <span class="n">make_wsgi_app</span><span class="p">(</span><span class="s1">&#39;examples/minimal/etc/mapproxy.yaml&#39;</span><span class="p">,</span> <span class="n">reloader</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="apache-mod-wsgi">
<span id="index-0"></span><h2>Apache mod_wsgi<a class="headerlink" href="#apache-mod-wsgi" title="Permalink to this headline"></a></h2>
<p>The Apache HTTP server can directly integrate Python application with the <a class="reference external" href="http://www.modwsgi.org/">mod_wsgi</a> extension. The benefit is that you don&#8217;t have to start another server. Read <a class="reference external" href="http://code.google.com/p/modwsgi/wiki/InstallationInstructions">mod_wsgi installation</a> for detailed instructions.</p>
<p><code class="docutils literal"><span class="pre">mod_wsgi</span></code> requires a server script that defines the configured WSGI function as <code class="docutils literal"><span class="pre">application</span></code>. See <a class="reference internal" href="#server-script"><span class="std std-ref">above</span></a>.</p>
<p>You need to modify your Apache <code class="docutils literal"><span class="pre">httpd.conf</span></code> as follows:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># if not loaded elsewhere</span>
<span class="n">LoadModule</span> <span class="n">wsgi_module</span> <span class="n">modules</span><span class="o">/</span><span class="n">mod_wsgi</span><span class="o">.</span><span class="n">so</span>

<span class="n">WSGIScriptAlias</span> <span class="o">/</span><span class="n">mapproxy</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">mapproxy</span><span class="o">/</span><span class="n">config</span><span class="o">.</span><span class="n">py</span>

<span class="o">&lt;</span><span class="n">Directory</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">mapproxy</span><span class="o">/&gt;</span>
  <span class="n">Order</span> <span class="n">deny</span><span class="p">,</span><span class="n">allow</span>
  <span class="n">Allow</span> <span class="kn">from</span> <span class="nn">all</span>
<span class="o">&lt;/</span><span class="n">Directory</span><span class="o">&gt;</span>
</pre></div>
</div>
<p><code class="docutils literal"><span class="pre">mod_wsgi</span></code> has a lot of options for more fine tuning. <code class="docutils literal"><span class="pre">WSGIPythonHome</span></code> or <code class="docutils literal"><span class="pre">WSGIPythonPath</span></code> lets you configure your <code class="docutils literal"><span class="pre">virtualenv</span></code> and  <code class="docutils literal"><span class="pre">WSGIDaemonProcess</span></code>/<code class="docutils literal"><span class="pre">WSGIProcessGroup</span></code> allows you to start multiple processes. See the <a class="reference external" href="http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives">mod_wsgi configuration directives documentation</a>. Using Mapnik also requires the <code class="docutils literal"><span class="pre">WSGIApplicationGroup</span></code> option.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On Windows only the <code class="docutils literal"><span class="pre">WSGIPythonPath</span></code> option is supported. Linux/Unix supports <code class="docutils literal"><span class="pre">WSGIPythonPath</span></code> and <code class="docutils literal"><span class="pre">WSGIPythonHome</span></code>. See also the <a class="reference external" href="https://code.google.com/p/modwsgi/wiki/VirtualEnvironments">mod_wsgi documentation for virtualenv</a> for detailed information when using multiple virtualenvs.</p>
</div>
<p>A more complete configuration might look like:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># if not loaded elsewhere</span>
<span class="n">LoadModule</span> <span class="n">wsgi_module</span> <span class="n">modules</span><span class="o">/</span><span class="n">mod_wsgi</span><span class="o">.</span><span class="n">so</span>

<span class="n">WSGIScriptAlias</span> <span class="o">/</span><span class="n">mapproxy</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">mapproxy</span><span class="o">/</span><span class="n">config</span><span class="o">.</span><span class="n">py</span>
<span class="n">WSGIDaemonProcess</span> <span class="n">mapproxy</span> <span class="n">user</span><span class="o">=</span><span class="n">mapproxy</span> <span class="n">group</span><span class="o">=</span><span class="n">mapproxy</span> <span class="n">processes</span><span class="o">=</span><span class="mi">8</span> <span class="n">threads</span><span class="o">=</span><span class="mi">25</span>
<span class="n">WSGIProcessGroup</span> <span class="n">mapproxy</span>
<span class="c1"># WSGIPythonHome should contain the bin and lib dir of your virtualenv</span>
<span class="n">WSGIPythonHome</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">mapproxy</span><span class="o">/</span><span class="n">venv</span>
<span class="n">WSGIApplicationGroup</span> <span class="o">%</span><span class="p">{</span><span class="n">GLOBAL</span><span class="p">}</span>

<span class="o">&lt;</span><span class="n">Directory</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">mapproxy</span><span class="o">/&gt;</span>
  <span class="n">Order</span> <span class="n">deny</span><span class="p">,</span><span class="n">allow</span>
  <span class="n">Require</span> <span class="nb">all</span> <span class="n">granted</span>  <span class="c1"># for Apache 2.4</span>
  <span class="c1"># Allow from all     # for Apache 2.2</span>
<span class="o">&lt;/</span><span class="n">Directory</span><span class="o">&gt;</span>
</pre></div>
</div>
</div>
<div class="section" id="behind-http-server-or-proxy">
<h2>Behind HTTP server or proxy<a class="headerlink" href="#behind-http-server-or-proxy" title="Permalink to this headline"></a></h2>
<p>There are Python HTTP servers available that can directly run MapProxy. Most of them are robust and efficient, but there are some odd HTTP clients out there that (mis)interpret the HTTP standard in various ways. It is therefor recommended to put a HTTP server or proxy in front that is mature and widely deployed (like <a class="reference external" href="http://httpd.apache.org/">Apache</a>, <a class="reference external" href="http://nginx.org">Nginx</a>, etc.).</p>
<div class="section" id="python-http-server">
<h3>Python HTTP Server<a class="headerlink" href="#python-http-server" title="Permalink to this headline"></a></h3>
<p>You need start these servers in the background on start up. It is recommended to create an init script for that or to use tools like <a class="reference external" href="http://upstart.ubuntu.com/">upstart</a> or <a class="reference external" href="http://supervisord.org/">supervisord</a>.</p>
<div class="section" id="gunicorn">
<h4>Gunicorn<a class="headerlink" href="#gunicorn" title="Permalink to this headline"></a></h4>
<p><a class="reference external" href="http://gunicorn.org/">Gunicorn</a> is a Python WSGI HTTP server for UNIX. Gunicorn use multiple processes but the process number is fixed. The default worker is synchronous, meaning that a process is blocked while it requests data from another server for example. You need to choose an asynchronous worker like <a class="reference external" href="http://pypi.python.org/pypi/eventlet">eventlet</a>.</p>
<p>You need a server script that creates the MapProxy application (see <a class="reference internal" href="#server-script"><span class="std std-ref">above</span></a>). The script needs to be in the directory from where you start <code class="docutils literal"><span class="pre">gunicorn</span></code> and it needs to end with <code class="docutils literal"><span class="pre">.py</span></code>.</p>
<p>To start MapProxy with the Gunicorn web server with four processes, the eventlet worker and our server script (without <code class="docutils literal"><span class="pre">.py</span></code>):</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">of</span><span class="o">/</span><span class="n">config</span><span class="o">.</span><span class="n">py</span><span class="o">/</span>
<span class="n">gunicorn</span> <span class="o">-</span><span class="n">k</span> <span class="n">eventlet</span> <span class="o">-</span><span class="n">w</span> <span class="mi">4</span> <span class="o">-</span><span class="n">b</span> <span class="p">:</span><span class="mi">8080</span> <span class="n">config</span><span class="p">:</span><span class="n">application</span>
</pre></div>
</div>
<p>An example upstart script (<code class="docutils literal"><span class="pre">/etc/init/mapproxy.conf</span></code>) might look like:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>start on runlevel [2345]
stop on runlevel [!2345]

respawn

setuid mapproxy
setgid mapproxy

chdir /etc/opt/mapproxy

exec /opt/mapproxy/bin/gunicorn -k eventlet -w 8 -b :8080 application \
    &gt;&gt;/var/log/mapproxy/gunicorn.log 2&gt;&amp;1
</pre></div>
</div>
</div>
<div class="section" id="spawning">
<h4>Spawning<a class="headerlink" href="#spawning" title="Permalink to this headline"></a></h4>
<p><a class="reference external" href="http://pypi.python.org/pypi/Spawning">Spawning</a> is another Python WSGI HTTP server for UNIX that supports multiple processes and multiple threads.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">of</span><span class="o">/</span><span class="n">config</span><span class="o">.</span><span class="n">py</span><span class="o">/</span>
<span class="n">spawning</span> <span class="n">config</span><span class="o">.</span><span class="n">application</span> <span class="o">--</span><span class="n">threads</span><span class="o">=</span><span class="mi">8</span> <span class="o">--</span><span class="n">processes</span><span class="o">=</span><span class="mi">4</span> \
  <span class="o">--</span><span class="n">port</span><span class="o">=</span><span class="mi">8080</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="http-proxy">
<h3>HTTP Proxy<a class="headerlink" href="#http-proxy" title="Permalink to this headline"></a></h3>
<p>You can either use a dedicated HTTP proxy like <a class="reference external" href="http://www.varnish-cache.org/">Varnish</a> or a general HTTP web server with proxy capabilities like Apache with <a class="reference external" href="http://httpd.apache.org/docs/current/mod/mod_proxy.html">mod_proxy</a> in front of MapProxy.</p>
<p>You need to set some HTTP headers so that MapProxy can generate capability documents with the URL of the proxy, instead of the local URL of the MapProxy application.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">Host</span></code> – is the hostname that clients use to acces MapProxy (i.e. the proxy)</li>
<li><code class="docutils literal"><span class="pre">X-Script-Name</span></code> – path of MapProxy when the URL is not <code class="docutils literal"><span class="pre">/</span></code> (e.g. <code class="docutils literal"><span class="pre">/mapproxy</span></code>)</li>
<li><code class="docutils literal"><span class="pre">X-Forwarded-Host</span></code> – alternative to <code class="docutils literal"><span class="pre">HOST</span></code></li>
<li><code class="docutils literal"><span class="pre">X-Forwarded-Proto</span></code> – should be <code class="docutils literal"><span class="pre">https</span></code> when the client connects with HTTPS</li>
</ul>
<div class="section" id="nginx">
<h4>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline"></a></h4>
<p>Here is an example for the <a class="reference external" href="http://nginx.org">Nginx</a> webserver with the included proxy module. It forwards all requests to <code class="docutils literal"><span class="pre">example.org/mapproxy</span></code> to <code class="docutils literal"><span class="pre">localhost:8181/</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>server {
  server_name example.org;
  location /mapproxy {
    proxy_pass http://localhost:8181;
    proxy_set_header Host $http_host;
    proxy_set_header X-Script-Name /mapproxy;
  }
}
</pre></div>
</div>
</div>
<div class="section" id="apache">
<h4>Apache<a class="headerlink" href="#apache" title="Permalink to this headline"></a></h4>
<p>Here is an example for the <a class="reference external" href="http://httpd.apache.org/">Apache</a> webserver with the included <code class="docutils literal"><span class="pre">mod_proxy</span></code> and <code class="docutils literal"><span class="pre">mod_headers</span></code> modules. It forwards all requests to <code class="docutils literal"><span class="pre">example.org/mapproxy</span></code> to <code class="docutils literal"><span class="pre">localhost:8181/</span></code></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">IfModule</span> <span class="n">mod_proxy</span><span class="o">.</span><span class="n">c</span><span class="o">&gt;</span>
  <span class="o">&lt;</span><span class="n">IfModule</span> <span class="n">mod_headers</span><span class="o">.</span><span class="n">c</span><span class="o">&gt;</span>
        <span class="o">&lt;</span><span class="n">Location</span> <span class="o">/</span><span class="n">mapproxy</span><span class="o">&gt;</span>
                <span class="n">ProxyPass</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8181</span>
                <span class="n">ProxyPassReverse</span>  <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8181</span>
                <span class="n">RequestHeader</span> <span class="n">add</span> <span class="n">X</span><span class="o">-</span><span class="n">Script</span><span class="o">-</span><span class="n">Name</span> <span class="s2">&quot;/mapproxy&quot;</span>
        <span class="o">&lt;/</span><span class="n">Location</span><span class="o">&gt;</span>
  <span class="o">&lt;/</span><span class="n">IfModule</span><span class="o">&gt;</span>
<span class="o">&lt;/</span><span class="n">IfModule</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>You need to make sure that both modules are loaded. The <code class="docutils literal"><span class="pre">Host</span></code> is already set to the right value by default.</p>
</div>
</div>
</div>
<div class="section" id="other-deployment-options">
<h2>Other deployment options<a class="headerlink" href="#other-deployment-options" title="Permalink to this headline"></a></h2>
<p>Refer to <a class="reference external" href="http://wsgi.readthedocs.org/en/latest/servers.html">http://wsgi.readthedocs.org/en/latest/servers.html</a> for a list of some available WSGI servers.</p>
<div class="section" id="fastcgi">
<h3>FastCGI<a class="headerlink" href="#fastcgi" title="Permalink to this headline"></a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Running MapProxy as a FastCGI server behind HTTP server is no longer advised for new setups since the used Python package (flup) is no longer maintained. Please refer to the <a class="reference external" href="http://mapproxy.org/docs/1.5.0/deployment.html">MapProxy 1.5.0 deployment documentation for more information on FastCGI</a>.</p>
</div>
</div>
</div>
<div class="section" id="performance">
<h2>Performance<a class="headerlink" href="#performance" title="Permalink to this headline"></a></h2>
<p>Because of the way Python handles threads in computing heavy applications (like MapProxy WMS is), you should choose a server that uses multiple processes (pre-forking based) for best performance.</p>
<p>The examples above are all minimal and you should read the documentation of your components to get the best performance with your setup.</p>
</div>
<div class="section" id="load-balancing-and-high-availablity">
<h2>Load Balancing and High Availablity<a class="headerlink" href="#load-balancing-and-high-availablity" title="Permalink to this headline"></a></h2>
<p>You can easily run multiple MapProxy instances in parallel and use a load balancer to distribute requests across all instances, but there are a few things to consider when the instances share the same tile cache with NFS or other network filesystems.</p>
<p>MapProxy uses file locks to prevent that multiple processes will request the same image twice from a source. This would typically happen when two or more requests for missing tiles are processed in parallel by MapProxy and these tiles belong to the same meta tile. Without locking MapProxy would request the meta tile for each request. With locking, only the first process will get the lock and request the meta tile. The other processes will wait till the the first process releases the lock and will then use the new created tile.</p>
<p>Since file locking doesn&#8217;t work well on most network filesystems you are likely to get errors when MapProxy writes these files on network filesystems. You should configure MapProxy to write all lock files on a local filesystem to prevent this. See <a class="reference internal" href="configuration.html#lock-dir"><span class="std std-ref">globals.cache.lock_dir</span></a> and <a class="reference internal" href="configuration.html#tile-lock-dir"><span class="std std-ref">globals.cache.tile_lock_dir</span></a>.</p>
<p>With this setup the locking will only be effective when parallel requests for tiles of the same meta tile go to the same MapProxy instance. Since these requests are typically made from the same client you should enable <em>sticky sessions</em> in you load balancer when you offer tiled services (WMTS/TMS/KML).</p>
</div>
<div class="section" id="logging">
<h2>Logging<a class="headerlink" href="#logging" title="Permalink to this headline"></a></h2>
<p>MapProxy uses the Python logging library for the reporting of runtime information, errors and warnings. You can configure the logging with Python code or with an ini-style configuration. Read the <a class="reference external" href="http://docs.python.org/howto/logging.html#configuring-logging">logging documentation for more information</a>.</p>
<div class="section" id="loggers">
<h3>Loggers<a class="headerlink" href="#loggers" title="Permalink to this headline"></a></h3>
<p>MapProxy uses multiple loggers for different parts of the system. The loggers build a hierarchy and are named in dotted-notation. <code class="docutils literal"><span class="pre">mapproxy</span></code> is the logger for everything, <code class="docutils literal"><span class="pre">mapproxy.source</span></code> is the logger for all sources, <code class="docutils literal"><span class="pre">mapproxy.source.wms</span></code> is the logger for all WMS sources, etc. If you configure on logger (e.g. <code class="docutils literal"><span class="pre">mapproxy</span></code>) then all sub-loggers will also use this configuration.</p>
<p>Here are the most important loggers:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">mapproxy.system</span></code></dt>
<dd>Logs information about the system and the installation (e.g. used projection library).</dd>
<dt><code class="docutils literal"><span class="pre">mapproxy.config</span></code></dt>
<dd>Logs information about the configuration.</dd>
<dt><code class="docutils literal"><span class="pre">mapproxy.source.XXX</span></code></dt>
<dd>Logs errors and warnings for service <code class="docutils literal"><span class="pre">XXX</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">mapproxy.source.request</span></code></dt>
<dd>Logs all requests to sources with URL, size in kB and duration in milliseconds. The duration is the time it took to receive the header of the response. The actual request duration might be longer, especially for larger images or when the network bandwith is limited.</dd>
</dl>
</div>
<div class="section" id="enabling-logging">
<h3>Enabling logging<a class="headerlink" href="#enabling-logging" title="Permalink to this headline"></a></h3>
<p>The <a class="reference internal" href="#deployment-testing"><span class="std std-ref">test server</span></a> is already configured to log all messages to the console (<code class="docutils literal"><span class="pre">stdout</span></code>). The other deployment options require a logging configuration.</p>
<div class="section" id="id7">
<h4>Server Script<a class="headerlink" href="#id7" title="Permalink to this headline"></a></h4>
<p>You can use the Python logging API or load an <code class="docutils literal"><span class="pre">.ini</span></code> configuration if you have a <a class="reference internal" href="#server-script"><span class="std std-ref">server script</span></a> for deployment.</p>
<p>The example script created with <code class="docutils literal"><span class="pre">mapproxy-util</span> <span class="pre">create</span> <span class="pre">-t</span> <span class="pre">wsgi-app</span></code> already contains code to load an <code class="docutils literal"><span class="pre">.ini</span></code> file. You just need to uncomment these lines and create a <code class="docutils literal"><span class="pre">log.ini</span></code> file. You can create an example <code class="docutils literal"><span class="pre">log.ini</span></code> with:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">mapproxy</span><span class="o">-</span><span class="n">util</span> <span class="n">create</span> <span class="o">-</span><span class="n">t</span> <span class="n">log</span><span class="o">-</span><span class="n">ini</span> <span class="n">log</span><span class="o">.</span><span class="n">ini</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="multimapproxy">
<span id="index-1"></span><span id="id8"></span><h2>MultiMapProxy<a class="headerlink" href="#multimapproxy" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.0.</span></p>
</div>
<p>You can run multiple MapProxy instances (configurations) within one process with the MultiMapProxy application.</p>
<p>MultiMapProxy can dynamically load configurations. You can put all configurations into one directory and MapProxy maps each file to a URL: <code class="docutils literal"><span class="pre">conf/proj1.yaml</span></code> is available at <code class="docutils literal"><span class="pre">http://hostname/proj1/</span></code>.</p>
<p>Each configuration will be loaded on demand and MapProxy caches each loaded instance. The configuration will be reloaded if the file changes.</p>
<p>MultiMapProxy as the following options:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">config_dir</span></code></dt>
<dd>The directory where MapProxy should look for configurations.</dd>
<dt><code class="docutils literal"><span class="pre">allow_listing</span></code></dt>
<dd>If set to <code class="docutils literal"><span class="pre">true</span></code>, MapProxy will list all available configurations at the root URL of your MapProxy. Defaults to <code class="docutils literal"><span class="pre">false</span></code>.</dd>
</dl>
<div class="section" id="id9">
<h3>Server Script<a class="headerlink" href="#id9" title="Permalink to this headline"></a></h3>
<p>There is a <code class="docutils literal"><span class="pre">make_wsgi_app</span></code> function in the <code class="docutils literal"><span class="pre">mapproxy.multiapp</span></code> package that creates configured MultiMapProxy WSGI application. Replace the <code class="docutils literal"><span class="pre">application</span></code> definition in your script as follows:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mapproxy.multiapp</span> <span class="k">import</span> <span class="n">make_wsgi_app</span>
<span class="n">application</span> <span class="o">=</span> <span class="n">make_wsgi_app</span><span class="p">(</span><span class="s1">&#39;/path/to.projects&#39;</span><span class="p">,</span> <span class="n">allow_listing</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


    </div>
  </div>
</div>
<footer class="footer">
  <div class="container">
    <p class="pull-right">
      <a href="#">Back to top</a>
    </p>
    <p>
     
       &copy; Copyright Oliver Tonnhofer, Omniscale, <a href="http://mapproxy.org/about">Legal</a>
     
     <br/>
     
       Last updated on 2018-01-07
     <br/>

     
       Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
     
   </p>
 </div>
</footer>
  </body>
</html>