Nginx

dna.utils.Nginx

class dna.utils.Nginx(default)[source]

Various utilities to interface with nginx

Parameters

default (str) – the url of the default server to proxy to

gen_config_with_port(domain, port, logs_pre='/var/log/nginx/', proxy_set_header={})[source]

Generate an nginx config that proxies domain to port

Parameters
  • domain (str) – the domain to proxy

  • port (str) – the port to proxy to

  • logs_pre (str) – the location of logs for this proxy pass (defaults to “/var/logs/nginx/”)

  • proxy_set_header (dict) – a dictionary of proxy headers to pass into nginx

Returns

the generated nginx config, as a string

gen_config_with_sock(domain, sock, logs_pre='/var/log/nginx/', proxy_set_header={})[source]

Generate an nginx config that proxies domain to sock

Parameters
  • domain (str) – the domain to proxy

  • sock (str) – the location of the unix socket file to proxy to

  • logs_pre (str) – the location of logs for this proxy pass (defaults to “/var/logs/nginx/”)

  • proxy_set_header (dict) – a dictionary of proxy headers to pass into nginx

Returns

the generated nginx config, as a string

gen_config(domain, proxy_pass, logs_pre, proxy_set_header={})[source]

Generate an nginx config that proxies domain to proxy_pass

If domain is a top-level domain, we include www.domain`. If domain is the instance’s default domain, we include default_server.

Parameters
  • domain (str) – the domain to proxy

  • proxy_pass (str) – the destination to pass to

  • logs_pre (str) – the location of logs for this proxy pass

  • proxy_set_header (dict) – a dictionary of proxy headers to pass into nginx

Returns

the generated nginx config, as a string

dna.utils.Block

class dna.utils.Block(name, *sections, **options)[source]

Represents a block in an nginx configuration

Parameters
  • name (str) – the name of this block

  • sections (list[Block]) – sub-blocks of this block

  • options (kwargs) – variables to include in this block

Important

If you’d like to include a return statement in your block, pass its value into the constructor as ret.