marvinpinto.docker-nginx
docker-nginx
An Ansible role for managing and running an nginx Docker container.
Requirements
This role has been tested on Ubuntu 14.04. Make sure you have a recent version of docker-py
and docker
installed because this role uses Ansible's Docker module.
We use tests/requirements.yml to install the dependency role: geerlingguy.docker. You can also run ansible-galaxy install -r tests/requirements.yml
or add the same content to your requirements.yml
file in your repository.
Examples
To install this module from Ansible Galaxy into the './roles' directory, run:
ansible-galaxy install marvinpinto.docker-nginx -p ./roles
You can use it in a playbook like this, assuming Docker is already set up:
- hosts: 'servers'
roles:
- role: geerlingguy.docker # Any role can be used to install Docker, but it's required
- role: 'marvinpinto.docker-nginx'
become: yes
nginx_conf: |
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
Check the defaults/main.yml for role variables that can be changed! If you need a playbook to set up Docker, check out the marvinpinto.docker role.
Configuration
You need to configure the following for reverse proxies:
nginx_reverse_proxy_proxies
: a list of reverse proxy configurations. Each configuration needs:nginx_reverse_proxy_backend_name
: string, name for the backend in the nginx confignginx_reverse_proxy_domains
: list of public-facing domains to be proxiednginx_reverse_proxy_backends
: list of backend servers with ports and other valid parametersnginx_reverse_proxy_config_name
: name for the proxy file (without the '.conf' extension)
Example Playbook
---
# file group_vars/nginx_docker_proxy
nginx_reverse_proxy_proxies:
- config_name: app1proxy
backend_name: my-backend-1
backends:
- localhost:1880 weight=2
- localhost:1881
domains:
- app1.192.168.88.10.xip.io
locations:
- /path/ # if your site is hosted on backend-name/path/
root_redirect_location: /path/ # for default redirection
- config_name: app2proxy
backend_name: my-backend-2
backends:
- localhost:1882
- localhost:1883 backup # backup server, used when primary is down
domains:
- app2.192.168.88.10.xip.io
balancer_config: least_conn; # Remember to add a semicolon at the end
License
Author Information
- Marvin Pinto
Collaborators
- Pablo Estigarribia (pablodav at gmail)
More Documentation
Notes About NGINX Settings
When adding backends, ensure that your server can resolve the DNS names before starting NGINX. If NGINX can't resolve the name, it won't start.
Developers
Help in testing this role: Testing Guidance
Ansible role to manage and run the nginx docker container.
ansible-galaxy install marvinpinto.docker-nginx