diff options
Diffstat (limited to 'roles/nginx/templates')
| -rw-r--r-- | roles/nginx/templates/nginx-validate.j2 | 38 | ||||
| -rw-r--r-- | roles/nginx/templates/nginx.conf.j2 | 33 |
2 files changed, 71 insertions, 0 deletions
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 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # {{ ansible_managed }} | ||
| 4 | # Atomic Nginx configuration validator wrapper for Ansible | ||
| 5 | |||
| 6 | TEMP_FILE="$1" | ||
| 7 | DEST_FILE="$2" | ||
| 8 | |||
| 9 | if [ -z "$TEMP_FILE" ] || [ -z "$DEST_FILE" ]; then | ||
| 10 | echo "Usage: nginx-validate <temp_file> <dest_file>" >&2 | ||
| 11 | exit 1 | ||
| 12 | fi | ||
| 13 | |||
| 14 | TIMESTAMP=$(date +%Y%m%d-%H%M%S) | ||
| 15 | BACKUP_FILE="${DEST_FILE}.${TIMESTAMP}.bak" | ||
| 16 | |||
| 17 | # Back up current destination if it exists | ||
| 18 | if [ -f "$DEST_FILE" ]; then | ||
| 19 | cp "$DEST_FILE" "$BACKUP_FILE" | ||
| 20 | fi | ||
| 21 | |||
| 22 | # Apply the rendered temporary file for testing | ||
| 23 | cp "$TEMP_FILE" "$DEST_FILE" | ||
| 24 | |||
| 25 | # Test master configuration | ||
| 26 | if nginx -t; then | ||
| 27 | rm -f "$BACKUP_FILE" | ||
| 28 | exit 0 | ||
| 29 | else | ||
| 30 | # Restore previous config on failure and clean up | ||
| 31 | if [ -f "$BACKUP_FILE" ]; then | ||
| 32 | cp "$BACKUP_FILE" "$DEST_FILE" | ||
| 33 | rm -f "$BACKUP_FILE" | ||
| 34 | else | ||
| 35 | rm -f "$DEST_FILE" | ||
| 36 | fi | ||
| 37 | exit 1 | ||
| 38 | 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 @@ | |||
| 1 | # {{ ansible_managed }} | ||
| 2 | user nginx; | ||
| 3 | error_log /var/log/nginx/error.log warn; | ||
| 4 | pid /var/run/nginx/nginx.pid; | ||
| 5 | |||
| 6 | worker_processes auto; | ||
| 7 | worker_rlimit_nofile 65535; | ||
| 8 | |||
| 9 | events { | ||
| 10 | worker_connections 4096; | ||
| 11 | use epoll; | ||
| 12 | multi_accept on; | ||
| 13 | } | ||
| 14 | |||
| 15 | http { | ||
| 16 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
| 17 | '$status $body_bytes_sent "$http_referer" ' | ||
| 18 | '"$http_user_agent" "$http_x_forwarded_for"'; | ||
| 19 | access_log /var/log/nginx/access.log main; | ||
| 20 | |||
| 21 | sendfile on; | ||
| 22 | tcp_nopush on; | ||
| 23 | tcp_nodelay on; | ||
| 24 | server_tokens off; | ||
| 25 | keepalive_timeout 65; | ||
| 26 | |||
| 27 | client_body_buffer_size 512k; | ||
| 28 | client_max_body_size 64M; | ||
| 29 | |||
| 30 | default_type application/octet-stream; | ||
| 31 | include /etc/nginx/mime.types; | ||
| 32 | include /etc/nginx/http.d/*.conf; | ||
| 33 | } | ||
