Ansible Role - Nginx
Go to file
Jeff Geerling c892b0a2fe Merge pull request #16 from Firfi/master
Restore compartability with geerlingguy-kibana, only include .conf files.
2015-05-16 06:50:44 -07:00
defaults Fix nginx_vhosts comment 2015-05-12 17:18:50 -03:00
handlers Fixes #10: Better organize os-specific tasks. 2015-02-20 23:15:01 -06:00
meta Add EL7 to supported platforms. 2014-11-11 10:39:30 -06:00
tasks Fixes #13: Allow configuration of default_release parameter for apt installation. 2015-02-25 07:59:24 -06:00
templates restore compartability with geerlingguy-kibana 2015-05-16 17:30:31 +07:00
tests Issue #6 and PR #8: Make nginx user more flexible. 2015-01-02 11:47:26 -06:00
vars PR #14: Change use of nginx_conf_path and nginx_vhost_path to match naming convention. 2015-05-12 17:47:15 -07:00
.travis.yml Update test. 2014-11-08 14:36:17 -06:00
README.md Issue #13: Document new nginx_default_release variable in README. 2015-02-25 08:02:18 -06:00

Ansible Role: Nginx

Build Status

Installs Nginx on RedHat/CentOS or Debian/Ubuntu linux servers.

This role installs and configures the latest version of Nginx from the Nginx yum repository (on RedHat-based systems) or via apt (on Debian-based systems). You will likely need to do extra setup work after this role has installed Nginx, like adding your own [virtualhost].conf file inside /etc/nginx/conf.d/, describing the location and options to use for your particular website.

Requirements

None.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

nginx_vhosts: []

A list of vhost definitions (server blocks) for Nginx virtual hosts. If left empty, you will need to supply your own virtual host configuration. See the commented example in defaults/main.yml for available server options. If you have a large number of customizations required for your server definition(s), you're likely better off managing the vhost configuration file yourself, leaving this variable set to [].

nginx_remove_default_vhost: false

Whether to remove the 'default' virtualhost configuration supplied by Nginx. Useful if you want the base / URL to be directed at one of your own virtual hosts configured in a separate .conf file.

nginx_upstreams: []

If you are configuring Nginx as a load balancer, you can define one or more upstream sets using this variable. In addition to defining at least one upstream, you would need to configure one of your server blocks to proxy requests through the defined upstream (e.g. proxy_pass http://myapp1;). See the commented example in defaults/main.yml for more information.

nginx_user: "nginx"

The user under which Nginx will run. Defaults to nginx for RedHat, and www-data for Debian.

nginx_worker_processes: "1"
nginx_worker_connections: "1024"

nginx_worker_processes should be set to the number of cores present on your machine. Connections (find this number with grep processor /proc/cpuinfo | wc -l). nginx_worker_connections is the number of connections per process. Set this higher to handle more simultaneous connections (and remember that a connection will be used for as long as the keepalive timeout duration for every client!).

nginx_error_log: "/var/log/nginx/error.log warn"
nginx_access_log: "/var/log/nginx/access.log main buffer=16k"

Configuration of the default error and access logs. Set to off to disable a log entirely.

nginx_sendfile: "on"
nginx_tcp_nopush: "on"
nginx_tcp_nodelay: "on"

TCP connection options. See this blog post for more information on these directives.

nginx_keepalive_timeout: "65"
nginx_keepalive_requests: "100"

Nginx keepalive settings. Timeout should be set higher (10s+) if you have more polling-style traffic (AJAX-powered sites especially), or lower (<10s) if you have a site where most users visit a few pages and don't send any further requests.

nginx_client_max_body_size: "64m"

This value determines the largest file upload possible, as uploads are passed through Nginx before hitting a backend like php-fpm. If you get an error like client intended to send too large body, it means this value is set too low.

nginx_proxy_cache_path: ""

Set as the proxy_cache_path directive in the nginx.conf file. By default, this will not be configured (if left as an empty string), but if you wish to use Nginx as a reverse proxy, you can set this to a valid value (e.g. "/var/cache/nginx keys_zone=cache:32m") to use Nginx's cache (further proxy configuration can be done in individual server configurations).

nginx_default_release: ""

(For Debian/Ubuntu only) Allows you to set a different repository for the installation of Nginx. As an example, if you are running Debian's wheezy release, and want to get a newer version of Nginx, you can install the wheezy-backports repository and set that value here, and Ansible will use that as the -t option while installing Nginx.

Dependencies

None.

Example Playbook

- hosts: server
  roles:
    - { role: geerlingguy.nginx }

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.