fabtools.require.nginx

Nginx

This module provides high-level tools for installing the nginx web server and managing the configuration of web sites.

See also

fabtools.nginx

fabtools.require.nginx.server(package_name='nginx')[source]

Require the nginx web server to be installed and running.

You can override the system package name, if you need to install a specific variant such as nginx-extras or nginx-light.

from fabtools import require

require.nginx.server()
fabtools.require.nginx.enabled(config)[source]

Require an nginx site to be enabled.

This will cause nginx to reload its configuration.

from fabtools import require

require.nginx.enabled('mysite')
fabtools.require.nginx.disabled(config)[source]

Require an nginx site to be disabled.

This will cause nginx to reload its configuration.

from fabtools import require

require.nginx.site_disabled('default')
fabtools.require.nginx.site(server_name, template_contents=None, template_source=None, enabled=True, check_config=True, **kwargs)[source]

Require an nginx site.

You must provide a template for the site configuration, either as a string (template_contents) or as the path to a local template file (template_source).

from fabtools import require

CONFIG_TPL = '''
server {
    listen      %(port)d;
    server_name %(server_name)s %(server_alias)s;
    root        %(docroot)s;
    access_log  /var/log/nginx/%(server_name)s.log;
}'''

require.nginx.site('example.com',
    template_contents=CONFIG_TPL,
    port=80,
    server_alias='www.example.com',
    docroot='/var/www/mysite',
)
fabtools.require.nginx.proxied_site(server_name, enabled=True, **kwargs)[source]

Require an nginx site for a proxied app.

This uses a predefined configuration template suitable for proxying requests to a backend application server.

Required keyword arguments are:

  • port: the port nginx should listen on
  • proxy_url: URL of backend application server
  • docroot: path to static files
from fabtools import require

require.nginx.proxied_site('example.com',
    port=80,
    proxy_url='http://127.0.0.1:8080/',
    docroot='/path/to/myapp/static',
)