1
0
mirror of https://github.com/dev-sec/ansible-nginx-hardening.git synced 2024-11-26 11:13:45 +01:00
ansible-nginx-hardening/tasks/main.yml

81 lines
2.3 KiB
YAML
Raw Normal View History

2016-07-26 12:28:52 +02:00
---
- name: config should not be worldwide read- or writeable
2018-08-15 18:16:50 +02:00
file:
path: "/etc/nginx"
mode: "o-rw"
owner: "root"
group: "root"
recurse: yes
2016-07-26 12:28:52 +02:00
- name: create additional configuration
2018-08-15 18:16:50 +02:00
template:
src: "hardening.conf.j2"
dest: "/etc/nginx/conf.d/90.hardening.conf"
2018-08-15 18:16:50 +02:00
owner: "root"
group: "root"
notify: restart nginx
2016-07-26 12:28:52 +02:00
- name: change configuration in main nginx.conf
2018-08-15 18:16:50 +02:00
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*server_tokens'
line: " server_tokens {{ nginx_server_tokens }};"
2018-08-15 18:16:50 +02:00
insertafter: "http {"
notify: restart nginx
- name: change ssl_protocols in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*ssl_protocols'
2018-11-18 10:11:00 +01:00
line: " ssl_protocols {{ nginx_ssl_protocols }};"
insertafter: "http {"
notify: restart nginx
- name: change ssl_prefer_server_ciphers in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*ssl_prefer_server_ciphers'
2018-11-18 10:11:00 +01:00
line: " ssl_prefer_server_ciphers {{ nginx_ssl_prefer_server_ciphers }};"
insertafter: "http {"
notify: restart nginx
2016-07-26 12:28:52 +02:00
- name: change client_max_body_size in main nginx.conf
2018-08-15 18:16:50 +02:00
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*client_max_body_size'
line: " client_max_body_size {{ nginx_client_max_body_size }};"
2018-08-15 18:16:50 +02:00
insertafter: "http {"
notify: restart nginx
2016-07-26 12:28:52 +02:00
- name: change client_body_buffer_size in main nginx.conf
2018-08-15 18:16:50 +02:00
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*client_body_buffer_size'
line: " client_body_buffer_size {{ nginx_client_body_buffer_size }};"
2018-08-15 18:16:50 +02:00
insertafter: "http {"
notify: restart nginx
2016-07-26 12:28:52 +02:00
- name: change keepalive_timeout in main nginx.conf
2018-08-15 18:16:50 +02:00
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*keepalive_timeout'
line: " keepalive_timeout {{ nginx_keepalive_timeout }};"
2018-08-15 18:16:50 +02:00
insertafter: "http {"
notify: restart nginx
2016-07-26 12:28:52 +02:00
- name: remove default.conf
2018-08-15 18:16:50 +02:00
file:
path: "{{ item }}"
2018-08-15 18:16:50 +02:00
state: absent
2016-07-26 12:28:52 +02:00
when: nginx_remove_default_site
notify: restart nginx
loop:
- "/etc/nginx/conf.d/default.conf"
- "/etc/nginx/sites-enabled/default"
2016-09-22 18:06:39 +02:00
- name: generate dh group
2018-11-18 10:11:00 +01:00
command: "openssl dhparam -out /etc/nginx/dh{{ nginx_dh_size }}.pem {{ nginx_dh_size }}"
args:
2018-11-18 10:11:00 +01:00
creates: "/etc/nginx/dh{{ nginx_dh_size }}.pem"
notify: restart nginx