NGINX Workers
This playbook provisions NetActuate virtual servers and configures them as NGINX worker nodes. Use this as a base for deploying web servers, reverse proxies, or load balancer backends.
Provisioning Playbook
Create the worker servers on NetActuate:
---
- hosts: localhost
connection: local
gather_facts: false
vars:
api_key: "{{ lookup('env', 'NETACTUATE_API_KEY') }}"
worker_count: 3
worker_plan: "VR2048x2x40"
worker_image: "ubuntu-24.04"
worker_locations:
- ashburn
- losangeles
- amsterdam
tasks:
- name: Create NGINX worker servers
netactuate.cloud.server:
api_key: "{{ api_key }}"
hostname: "nginx-worker-{{ item }}"
plan: "{{ worker_plan }}"
location: "{{ worker_locations[item | int % worker_locations | length] }}"
image: "{{ worker_image }}"
state: present
loop: "{{ range(0, worker_count) | list }}"
register: workers
- name: Add workers to in-memory inventory
add_host:
name: "{{ item.ip_address }}"
groups: nginx_workers
loop: "{{ workers.results }}"
Configuration Playbook
Install and configure NGINX on the provisioned workers:
---
- hosts: nginx_workers
become: true
gather_facts: true
vars:
nginx_worker_processes: "auto"
nginx_worker_connections: 1024
tasks:
- name: Install NGINX
apt:
name: nginx
state: present
update_cache: true
- name: Configure NGINX
copy:
dest: /etc/nginx/nginx.conf
content: |
user www-data;
worker_processes {{ nginx_worker_processes }};
pid /run/nginx.pid;
events {
worker_connections {{ nginx_worker_connections }};
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
notify: Restart NGINX
- name: Create default site configuration
copy:
dest: /etc/nginx/sites-available/default
content: |
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /health {
access_log off;
return 200 "OK\n";
add_header Content-Type text/plain;
}
}
notify: Restart NGINX
- name: Enable default site
file:
src: /etc/nginx/sites-available/default
dest: /etc/nginx/sites-enabled/default
state: link
- name: Start and enable NGINX
systemd:
name: nginx
state: started
enabled: true
handlers:
- name: Restart NGINX
systemd:
name: nginx
state: restarted
Running the Playbooks
Run provisioning and configuration together:
ansible-playbook provision-nginx-workers.yml
ansible-playbook -i inventory.ini configure-nginx-workers.yml
Or combine them into a single playbook with both plays.
Customization
- Adjust
worker_countandworker_locationsto match your deployment needs. - Modify the NGINX configuration template for your application requirements.
- Add SSL configuration using the Add-On Playbooks.
Need Help?
If you need assistance deploying NGINX workers, visit our support page.