From 782e4429c89c6e91cd9aa7e5ba59517a52200dcd Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Thu, 22 Oct 2026 23:12:08 +0300 Subject: feat: add nginx --- roles/nginx/templates/nginx-validate.j2 | 38 +++++++++++++++++++++++++++++++++ roles/nginx/templates/nginx.conf.j2 | 33 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 roles/nginx/templates/nginx-validate.j2 create mode 100644 roles/nginx/templates/nginx.conf.j2 (limited to 'roles/nginx/templates') diff --git a/roles/nginx/templates/nginx-validate.j2 b/roles/nginx/templates/nginx-validate.j2 new file mode 100644 index 0000000..81c6fb8 --- /dev/null +++ b/roles/nginx/templates/nginx-validate.j2 @@ -0,0 +1,38 @@ +#!/bin/sh + +# {{ ansible_managed }} +# Atomic Nginx configuration validator wrapper for Ansible + +TEMP_FILE="$1" +DEST_FILE="$2" + +if [ -z "$TEMP_FILE" ] || [ -z "$DEST_FILE" ]; then + echo "Usage: nginx-validate " >&2 + exit 1 +fi + +TIMESTAMP=$(date +%Y%m%d-%H%M%S) +BACKUP_FILE="${DEST_FILE}.${TIMESTAMP}.bak" + +# Back up current destination if it exists +if [ -f "$DEST_FILE" ]; then + cp "$DEST_FILE" "$BACKUP_FILE" +fi + +# Apply the rendered temporary file for testing +cp "$TEMP_FILE" "$DEST_FILE" + +# Test master configuration +if nginx -t; then + rm -f "$BACKUP_FILE" + exit 0 +else + # Restore previous config on failure and clean up + if [ -f "$BACKUP_FILE" ]; then + cp "$BACKUP_FILE" "$DEST_FILE" + rm -f "$BACKUP_FILE" + else + rm -f "$DEST_FILE" + fi + exit 1 +fi diff --git a/roles/nginx/templates/nginx.conf.j2 b/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..110fa02 --- /dev/null +++ b/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,33 @@ +# {{ ansible_managed }} +user nginx; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx/nginx.pid; + +worker_processes auto; +worker_rlimit_nofile 65535; + +events { + worker_connections 4096; + use epoll; + multi_accept on; +} + +http { + 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; + tcp_nopush on; + tcp_nodelay on; + server_tokens off; + keepalive_timeout 65; + + client_body_buffer_size 512k; + client_max_body_size 64M; + + default_type application/octet-stream; + include /etc/nginx/mime.types; + include /etc/nginx/http.d/*.conf; +} -- cgit v1.3.1