nekeal.nginx

Ansible Role: Nginx

CI

Note: It's recommended to use the official NGINX Ansible role from NGINX, Inc.

This role installs Nginx on different operating systems like RedHat/CentOS, Debian/Ubuntu, Archlinux, FreeBSD, or OpenBSD.

It installs and configures the latest version of Nginx from their respective installation sources (yum for RedHat, apt for Debian, pacman for Archlinux, etc.). After installation, you will likely need to add your own virtualhost configuration file located in /etc/nginx/conf.d/.

Requirements

None.

Role Variables

Here are some available variables with their default values (see defaults/main.yml):

  • nginx_listen_ipv6: true: This controls whether to listen on IPv6 for all virtual hosts managed by this role.

  • nginx_selfsigned_certificate_directory: /etc/nginx/ssl: Directory for self-signed certificate files.

  • nginx_copy_missing_certs: yes: Defines if the role should copy self-signed certificates for any missing virtual hosts.

  • nginx_vhosts: []: List of virtual host configurations for Nginx. If empty, you'll need to provide your own configurations.

Example of a virtual host configuration:

nginx_vhosts:
  - name: localhost-django
    server_names:
      - "localhost"
    ...

In this example, if a required certificate is missing, it will be copied from the specified self-signed certificate directory.

  • nginx_remove_default_vhost: false: Controls whether to remove the default virtual host configuration provided by Nginx.

  • nginx_upstreams: []: If using Nginx as a load balancer, you can define upstream servers with this variable.

  • nginx_user: "nginx": User under which Nginx runs, defaults vary by OS.

  • nginx_worker_processes: "{{ ansible_processor_vcpus|default(ansible_processor_count) }}": Sets the number of Nginx worker processes based on your machine's cores.

  • nginx_keepalive_timeout: "65": Sets Nginx keepalive timeout duration.

  • nginx_client_max_body_size: "64m": Maximum file size for uploads. Increase this if you encounter upload errors.

  • nginx_service_state: started: Default state for the Nginx service after installation.

Overriding Configuration Templates

If you need to customize settings beyond the provided variables, you can use your own configuration templates:

nginx_conf_template: "nginx.conf.j2"
nginx_vhost_template: "vhost.j2"

You can also set template settings per virtual host:

nginx_vhosts:
  - listen: "80 default_server"
    template: "{{ playbook_dir }}/templates/site1.example.com.vhost.j2"

Example: Configure gzip in Nginx Configuration

To set up gzip compression, point to a custom template:

nginx_conf_template: "{{ playbook_dir }}/templates/nginx.conf.j2"

Then create a child template extending the default one, adding specific configurations.

Dependencies

None.

Example Playbook

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

License

MIT / BSD

Author Information

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

Informazioni sul progetto

Nginx installation for Linux, FreeBSD and OpenBSD.

Installa
ansible-galaxy install nekeal.nginx
Licenza
mit
Download
114
Proprietario