Page MenuHomeSealhub

No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml
index a24d995..5698b87 100644
--- a/roles/nginx/tasks/main.yml
+++ b/roles/nginx/tasks/main.yml
@@ -1,135 +1,136 @@
- name: Install nginx, certbot and geoip-database
apt:
name:
- nginx
- certbot
- libnginx-mod-http-geoip
- geoip-database
state: latest
update_cache: true
- name: Update Nginx include path to only match .conf files
ansible.builtin.replace:
path: /etc/nginx/nginx.conf
regexp: 'include /etc/nginx/sites-enabled/\*;'
replace: "include /etc/nginx/sites-enabled/*.conf;"
- name: Create JSON logs config in nginx conf
blockinfile:
path: /etc/nginx/nginx.conf
block: |
log_format json_analytics escape=json '{'
'"msec": "$msec", ' # request unixtime in seconds with a milliseconds resolution
'"connection": "$connection", ' # connection serial number
'"connection_requests": "$connection_requests", ' # number of requests made in connection
'"pid": "$pid", ' # process pid
'"request_id": "$request_id", ' # the unique request id
'"request_length": "$request_length", ' # request length (including headers and body)
'"remote_addr": "$remote_addr", ' # client IP
'"remote_user": "$remote_user", ' # client HTTP username
'"remote_port": "$remote_port", ' # client port
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", ' # local time in the ISO 8601 standard format
'"request": "$request", ' # full path no arguments if the request
'"request_uri": "$request_uri", ' # full path and arguments if the request
'"args": "$args", ' # args
'"status": "$status", ' # response status code
'"body_bytes_sent": "$body_bytes_sent", ' # the number of body bytes exclude headers sent to a client
'"bytes_sent": "$bytes_sent", ' # the number of bytes sent to a client
'"http_referer": "$http_referer", ' # HTTP referer
'"http_user_agent": "$http_user_agent", ' # user agent
'"http_x_forwarded_for": "$http_x_forwarded_for", ' # http_x_forwarded_for
'"http_host": "$http_host", ' # the request Host: header
'"server_name": "$server_name", ' # the name of the vhost serving the request
'"request_time": "$request_time", ' # request processing time in seconds with msec resolution
'"upstream": "$upstream_addr", ' # upstream backend server for proxied requests
'"upstream_connect_time": "$upstream_connect_time", ' # upstream handshake time incl. TLS
'"upstream_header_time": "$upstream_header_time", ' # time spent receiving upstream headers
'"upstream_response_time": "$upstream_response_time", ' # time spend receiving upstream body
'"upstream_response_length": "$upstream_response_length", ' # upstream response length
'"upstream_cache_status": "$upstream_cache_status", ' # cache HIT/MISS where applicable
'"ssl_protocol": "$ssl_protocol", ' # TLS protocol
'"ssl_cipher": "$ssl_cipher", ' # TLS cipher
'"scheme": "$scheme", ' # http or https
'"request_method": "$request_method", ' # request method
'"server_protocol": "$server_protocol", ' # request protocol, like HTTP/1.1 or HTTP/2.0
'"pipe": "$pipe", ' # "p" if request was pipelined, "." otherwise
'"gzip_ratio": "$gzip_ratio", '
'"http_cf_ray": "$http_cf_ray",'
'"geoip_country_code": "$geoip_country_code"'
'}';
insertafter: "http {"
marker: "# {mark} json logger syntax"
- name: "Enable the GeoIP module"
lineinfile:
path: "/etc/nginx/nginx.conf"
line: "geoip_country /usr/share/GeoIP/GeoIP.dat;"
insertafter: "http {"
- name: Update Nginx include path to only match .conf files
ansible.builtin.replace:
path: /etc/nginx/nginx.conf
regexp: "access_log .*;"
replace: "access_log /var/log/nginx/access.log.json json_analytics;"
- name: Remove default site if exists
file:
path: /etc/nginx/sites-enabled/default
state: absent
- name: Enable stub site
template:
src: "stub.conf.j2"
dest: /etc/nginx/sites-enabled/stub.conf
- name: Reload Nginx
ansible.builtin.service:
name: nginx
state: reloaded
- name: "Setup cron to attempt cert renewal every night"
cron:
name: "renew all letsencrypt certificates"
minute: 30
hour: 2
job: "/usr/bin/certbot renew --webroot && systemctl reload nginx"
- name: make sure sites-enabled directory exists
file:
path: /etc/nginx/sites-enabled
state: "directory"
- community.general.ufw:
rule: allow
port: "80"
- community.general.ufw:
rule: allow
port: "443"
- name: Configure logrotate for nginx JSON access log
copy:
dest: /etc/logrotate.d/nginx-json-access
owner: root
group: root
mode: "0644"
content: |
/var/log/nginx/access.log.json {
daily
rotate 14
compress
+ size 200M
delaycompress
missingok
notifempty
create 0640 www-data adm
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi \
endscript
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 9, 13:37 (12 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1182201
Default Alt Text
(5 KB)

Event Timeline