diff --git a/defaults/main.yml b/defaults/main.yml index 6d44bc9..0531b30 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,5 @@ --- +nginx_official_repo_enabled: True nginx_user: nginx nginx_group: nginx nginx_worker_processes: 1 @@ -7,12 +8,13 @@ nginx_open_ports: - 80 - 443 nginx_tls_enabled: False -nginx_tls_cert: "" -nginx_tls_private_key: "" -nginx_tls_intermediate_ca: "" +# nginx_tls_cert: +# nginx_tls_private_key: +# nginx_tls_intermediate_ca: +nginx_vhosts_dir: /var/www/vhosts nginx_pfs_enabled: False -nginx_dhparam_size: '4069' -nginx_dhparam_file: '/etc/pki/tls/certs/dhparam-{{ nginx_dhparam_size }}.pem' +nginx_dhparam_size: 4069 +nginx_dhparam_file: "/etc/pki/tls/certs/dhparam-{{ nginx_dhparam_size }}.pem" nginx_tls_cert_file: "/etc/pki/tls/certs/my-chained.crt" nginx_tls_intermediate_ca_file: "/etc/pki/tls/certs/my-intermediate.crt" nginx_tls_private_key_file: "/etc/pki/tls/private/my-private.key" diff --git a/tasks/install.yml b/tasks/install.yml index b0e63ad..b136d30 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -8,6 +8,7 @@ baseurl: "https://nginx.org/packages/centos/{{ ansible_distribution_major_version }}/$basearch/" gpgkey: https://nginx.org/keys/nginx_signing.key gpgcheck: yes + when: nginx_official_repo_enabled - name: Installing nginx yum: @@ -30,18 +31,18 @@ - name: Prepare vhost directories file: - path: '{{ item }}' + path: "{{ item }}" state: directory owner: nginx group: nginx mode: 0750 with_items: - - /var/www/vhosts - - /var/www/vhosts/default + - "{{ nginx_vhosts_dir }}" + - "{{ nginx_vhosts_dir }}/default" - name: Prepare nginx directories file: - path: '{{ item }}' + path: "{{ item }}" state: directory owner: root group: root @@ -52,8 +53,8 @@ - name: Update nginx.conf template: - src: 'etc/nginx/nginx.conf.j2' - dest: '/etc/nginx/nginx.conf' + src: etc/nginx/nginx.conf.j2 + dest: "/etc/nginx/nginx.conf" owner: root group: root mode: 0640 @@ -80,7 +81,7 @@ path: /etc/nginx/conf.d/default.conf state: absent - - name: Add default page config + - name: Add default page configuration file template: src: 'etc/nginx/sites-available/default.j2' dest: '/etc/nginx/sites-available/default' diff --git a/templates/etc/nginx/nginx.conf.j2 b/templates/etc/nginx/nginx.conf.j2 index fa5c369..6a32fed 100644 --- a/templates/etc/nginx/nginx.conf.j2 +++ b/templates/etc/nginx/nginx.conf.j2 @@ -5,52 +5,50 @@ worker_processes {{ nginx_worker_processes }}; error_log /var/log/nginx/error.log; pid /run/nginx.pid; - events { - worker_connections {{ nginx_worker_connections }}; + worker_connections {{ nginx_worker_connections }}; } - http { - include /etc/nginx/mime.types; - default_type application/octet-stream; + include /etc/nginx/mime.types; + default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; + 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; + access_log /var/log/nginx/access.log main; - sendfile on; - tcp_nopush on; - tcp_nodelay on; - types_hash_max_size 2048; - server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + types_hash_max_size 2048; + server_tokens off; - ## Buffers - client_body_buffer_size 10K; - client_header_buffer_size 1k; - client_max_body_size 8m; + ## Buffers + client_body_buffer_size 10K; + client_header_buffer_size 1k; + client_max_body_size 8m; - ## Timeouts - client_body_timeout 12; - client_header_timeout 12; - keepalive_timeout 15; - send_timeout 10; + ## Timeouts + client_body_timeout 12; + client_header_timeout 12; + keepalive_timeout 15; + send_timeout 10; - ## Gzip Settings - gzip on; - gzip_comp_level 2; - gzip_min_length 1000; - gzip_proxied expired no-cache no-store private auth; - gzip_types text/plain application/x-javascript text/xml text/css application/xml; + ## Gzip Settings + gzip on; + gzip_comp_level 2; + gzip_min_length 1000; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain application/x-javascript text/xml text/css application/xml; - # Load modular configuration files from the /etc/nginx/conf.d directory. - # See http://nginx.org/en/docs/ngx_core_module.html#include - # for more information. - include /etc/nginx/conf.d/*.conf; + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; - ## Virtual Host Configs - include /etc/nginx/sites-enabled/*; - server_names_hash_bucket_size 64; + ## Virtual Host Configs + include /etc/nginx/sites-enabled/*; + server_names_hash_bucket_size 64; }