Unify nginx configuration
This creates a simple base configuration skeleton, that other configuration can be easily loaded into.
This commit is contained in:
6
ansible/roles/nginx/files/nginx-https-redirect.conf
Normal file
6
ansible/roles/nginx/files/nginx-https-redirect.conf
Normal file
@ -0,0 +1,6 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
access_log off;
|
||||
return 308 https://$server_name$request_uri;
|
||||
}
|
40
ansible/roles/nginx/files/nginx.conf
Normal file
40
ansible/roles/nginx/files/nginx.conf
Normal file
@ -0,0 +1,40 @@
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
pcre_jit on;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
server_tokens off;
|
||||
|
||||
types_hash_max_size 2048;
|
||||
types_hash_bucket_size 128;
|
||||
|
||||
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;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
include /etc/nginx/http.d/*.conf;
|
||||
}
|
||||
|
||||
stream {
|
||||
ssl_preread on;
|
||||
|
||||
include /etc/nginx/stream.d/*.conf;
|
||||
}
|
5
ansible/roles/nginx/handlers/main.yml
Normal file
5
ansible/roles/nginx/handlers/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: reload nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
become: true
|
38
ansible/roles/nginx/tasks/main.yml
Normal file
38
ansible/roles/nginx/tasks/main.yml
Normal file
@ -0,0 +1,38 @@
|
||||
- name: Install nginx
|
||||
import_role:
|
||||
name: nginxinc.nginx
|
||||
when: ansible_os_family != 'Archlinux'
|
||||
become: true
|
||||
|
||||
- name: Install nginx on Arch
|
||||
package:
|
||||
name: nginx
|
||||
when: ansible_os_family == 'Archlinux'
|
||||
become: true
|
||||
|
||||
- name: Create config directories
|
||||
file:
|
||||
path: /etc/nginx/{{ item }}
|
||||
state: directory
|
||||
mode: "0755"
|
||||
loop:
|
||||
- http.d
|
||||
- stream.d
|
||||
become: true
|
||||
|
||||
- name: Install config
|
||||
template:
|
||||
src: files/nginx.conf
|
||||
dest: /etc/nginx/nginx.conf
|
||||
validate: nginx -t -c %s
|
||||
mode: "0644"
|
||||
become: true
|
||||
notify: reload nginx
|
||||
|
||||
- name: Install HTTPS redirect
|
||||
template:
|
||||
src: files/nginx-https-redirect.conf
|
||||
dest: /etc/nginx/http.d/https-redirect.conf
|
||||
mode: "0644"
|
||||
become: true
|
||||
notify: reload nginx
|
Reference in New Issue
Block a user