Nginx

Nginx process management.

Use this module to configure and manage a dedicated nginx server.

Classes

class servermgr.nginx.Manager(host, port, base_dir, http_root='', *args, **kwargs)[source]

Nginx manager object.

Parameters:
  • host (string) – the interface to listen on.
  • port (int) – the post to listen on.
  • base_dir (string) – the base directory for logs and configuration files.
add_fastcgi_mapping(url_prefix, destination)

Forward requests matching url_prefix to the fastcgi server at destination.

Parameters:
  • url_prefix (string) – url prefix.
  • destination (string) – destination
add_filesystem_mapping(url_prefix, directory)

Add a mapping from a URL prefix to a filesystem location.

Parameters:
  • url_prefix (string) – url prefix.
  • directory – directory name
add_http_mapping(url_prefix, destination)

Act as a reverse proxy, sending URLs matching url_prefix to destination.

Parameters:
  • url_prefix (string) – url prefix.
  • destination (string) – destination http server
add_redirect_mapping(url_prefix, pattern, rewrite)

URLs that have the prefix prefix are then matched against the regular expression pattern and rewritten using destination, which may use matched subexpressions from pattern. See Nginx Rewrite Module for details.

Parameters:
  • url_prefix (string) – url prefix.
  • pattern (string, regular expression) – the re pattern to match against
  • rewrite (string) – the rewrite pattern, which may include matched patterns from pattern.
health()[source]

Check on the health of the Solr server.

Raises :base.WorkerError if the server is not responding.
process

Return the process object.

ready_wait(timeout=10.0, verbose=False)

Wait until the worker subprocess is responding to requests.

Parameters:
  • timeout (float, seconds) – Give the server this many seconds to start. If the timeout expires before the server has started, kill the server and raise WorkerError.
Raises :

WorkerError if the worker is not ready within the time limit.

Raises :

WorkerError if there is no subprocess.

start(wait=True, timeout=10.0)[source]

Start the http server.

Parameters:
  • wait – If true, call self.ready_wait() after starting the subprocess.
  • timeout (float, number of seconds) – When calling ready_wait(), use this timeout value.
Raises :

base.WorkerError if the worker hasn’t started before timeout elapses.

stop(wait=True)

Terminate the worker subprocess.

Parameters:
  • wait (boolean) – If True, wait for the worker to exit.
wait()

Wait for the worker process to exit.

Private Classes

class servermgr.nginx._ConfigBuilder(host, port, base_dir, http_root)[source]

Nginx configuration file builder.

This mixin class provides the methods that can be used to add various types of URL mappings to an Nginx config file.

add_fastcgi_mapping(url_prefix, destination)[source]

Forward requests matching url_prefix to the fastcgi server at destination.

Parameters:
  • url_prefix (string) – url prefix.
  • destination (string) – destination
add_filesystem_mapping(url_prefix, directory)[source]

Add a mapping from a URL prefix to a filesystem location.

Parameters:
  • url_prefix (string) – url prefix.
  • directory – directory name
add_http_mapping(url_prefix, destination)[source]

Act as a reverse proxy, sending URLs matching url_prefix to destination.

Parameters:
  • url_prefix (string) – url prefix.
  • destination (string) – destination http server
add_redirect_mapping(url_prefix, pattern, rewrite)[source]

URLs that have the prefix prefix are then matched against the regular expression pattern and rewritten using destination, which may use matched subexpressions from pattern. See Nginx Rewrite Module for details.

Parameters:
  • url_prefix (string) – url prefix.
  • pattern (string, regular expression) – the re pattern to match against
  • rewrite (string) – the rewrite pattern, which may include matched patterns from pattern.

Running nginx.py

servermgr.nginx.main()[source]

You can use this script to start a copy of Nginx.

Usage: nginx.py [–help] [-h HOST] [-p PORT] [-d DATADIR] [-f FSMAP] [-r REDIRECT] [-c FCGI] [-t HTTP]

optional arguments:
--help show this help message and exit
-h HOST, --host=HOST
 listener hostname
-p PORT, --port=PORT
 listener port
-d DATADIR, --datadir=DATADIR
 data directory
--fsmap FSMAP add a filesystem mapping
--redirect REDIRECT
 add a redirect
--fcgi FCGI add a fastcgi mapping
--http HTTP add a http mapping
--config print the generated config file and exit
To specify a filesystem mapping, use the option:
–fsmap=/some_url_prefix,/somedirectory
To map a url prefix to a webapp using fcgi, use:
–fcgi=/some_url_prefix,host:port
To make a url prefix a reverse proxy for another http server, use:
–http=/url_prefix,some_other_url
To make a url redirect elsewhere:
–redirect=/url_prefix,pattern,rewrite

Table Of Contents

Previous topic

Base

Next topic

Postgres

This Page