init
This commit is contained in:
4
ansible/roles/nginx/handlers/main.yaml
Normal file
4
ansible/roles/nginx/handlers/main.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Restart nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
57
ansible/roles/nginx/tasks/main.yaml
Normal file
57
ansible/roles/nginx/tasks/main.yaml
Normal file
@@ -0,0 +1,57 @@
|
||||
- name: Install nginx
|
||||
package:
|
||||
name: nginx
|
||||
state: latest
|
||||
|
||||
- name: Install nginx.conf
|
||||
template:
|
||||
src: templates/nginx.conf.j2
|
||||
dest: /etc/nginx/nginx.conf
|
||||
owner: nginx
|
||||
group: nginx
|
||||
mode: '0644'
|
||||
notify: Restart nginx
|
||||
|
||||
- name: Create nginx ssl directory
|
||||
file:
|
||||
path: /etc/nginx/ssl
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Generate dhparams
|
||||
command:
|
||||
cmd: openssl dhparam -out /etc/nginx/ssl/dhparam.pem 4096
|
||||
creates: /etc/nginx/ssl/dhparam.pem
|
||||
notify: Restart nginx
|
||||
|
||||
- name: Start and enable nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: Permanently enable http service
|
||||
ansible.posix.firewalld:
|
||||
service: http
|
||||
state: enabled
|
||||
permanent: true
|
||||
immediate: true
|
||||
offline: true
|
||||
|
||||
- name: Permanently enable https service
|
||||
ansible.posix.firewalld:
|
||||
service: https
|
||||
state: enabled
|
||||
permanent: true
|
||||
immediate: true
|
||||
offline: true
|
||||
|
||||
- name: Create nginx vhosts
|
||||
template:
|
||||
src: templates/vhost.conf.j2
|
||||
dest: /etc/nginx/conf.d/{{ inventory_hostname }}.conf
|
||||
owner: nginx
|
||||
group: nginx
|
||||
mode: '0644'
|
||||
notify: Restart nginx
|
||||
|
||||
18
ansible/roles/nginx/tasks/templates/nginx.conf.j2
Normal file
18
ansible/roles/nginx/tasks/templates/nginx.conf.j2
Normal file
@@ -0,0 +1,18 @@
|
||||
user nginx;
|
||||
worker_processes 2;
|
||||
error_log /var/log/nginx/main_error.log;
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
http {
|
||||
include 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"';
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/http_error.log;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
include conf.d/*;
|
||||
}
|
||||
48
ansible/roles/nginx/tasks/templates/vhost.conf.j2
Normal file
48
ansible/roles/nginx/tasks/templates/vhost.conf.j2
Normal file
@@ -0,0 +1,48 @@
|
||||
server {
|
||||
listen [::]:80 ipv6only=off default_server;
|
||||
server_name {{ inventory_hostname }};
|
||||
root /srv/http/{{ inventory_hostname }}/html;
|
||||
|
||||
# Allow lego to renew certs here using its own http server, we just proxy
|
||||
location /.well-known/acme-challenge {
|
||||
proxy_pass http://127.0.0.1:81;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://{{ inventory_hostname }}$request_uri;
|
||||
index index.htm index.html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
server {
|
||||
listen [::]:443 ssl ipv6only=off default_server;
|
||||
http2 on;
|
||||
ssl_certificate /etc/nginx/ssl/{{ inventory_hostname}}.crt;
|
||||
ssl_certificate_key /etc/nginx/ssl/{{ inventory_hostname}}.key;
|
||||
ssl_trusted_certificate /etc/nginx/ssl/{{ inventory_hostname}}.issuer.crt;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_cache shared:SSL:50m;
|
||||
ssl_session_tickets off;
|
||||
ssl_protocols TLSv1.3;
|
||||
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
|
||||
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
|
||||
ssl_prefer_server_ciphers on;
|
||||
add_header Strict-Transport-Security max-age=15768000;
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
server_name {{ inventory_hostname }};
|
||||
|
||||
location / {
|
||||
client_max_body_size 512M;
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Connection $http_connection;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user