Commit 91068ec1 authored by Va4o4o's avatar Va4o4o
Browse files

Added auto deploy vhosts & another changes

parent 6903d566
If you see it, that's works and name is {{ item.virtual_domain }} port {{ item.listen_port }}
user {{ nginx_user }};
worker_processes {{ worker_processes }};
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections {{ worker_connections }};
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
server {
listen {{ item.listen_port }};
server_name {{ item.virtual_domain }} www.{{ item.virtual_domain }};
root /var/www/html/{{ item.virtual_domain }};
access_log /var/log/nginx/{{ item.virtual_domain }}_access_log;
error_log /var/log/nginx/{{ item.virtual_domain }}_error_log;
location / {
index index.html index.htm;
}
}
---
- hosts:
- all
vars:
nginx_user: www-data
worker_processes: auto
worker_connections: 2048
client_max_body_size: 512M
vhosts:
-
virtual_domain: va4o4o-0.local
listen_port: 80
-
virtual_domain: va4o4o-1.local
listen_port: 81
tasks:
- name: Install NGINX
apt:
name: nginx
state: present
notify: NGINX start
notify:
- NGINX start
- name: Create home directory for www
file:
path: /var/www/html/{{ item.virtual_domain }}
state: directory
loop: "{{ vhosts }}"
- name: Replace NGINX config
template:
src: mytemplates/nginx.conf.j2
dest: /etc/nginx/nginx.conf
- name: Add virtualhost config file
template:
src: mytemplates/vhost.conf.j2
dest: /etc/nginx/sites-available/{{ item.virtual_domain }}.conf
mode: 0644
loop: "{{ vhosts }}"
- name: Create symlink from available to enable
file:
dest: /etc/nginx/sites-enabled/{{ item.virtual_domain }}.conf
src: /etc/nginx/sites-available/{{ item.virtual_domain }}.conf
state: link
loop: "{{ vhosts }}"
- name: Delete symlink default
file:
path: /etc/nginx/sites-enabled/default
state: absent
- name: copy index.html
template:
src: mytemplates/index.html.j2
dest: /var/www/html/{{ item.virtual_domain }}/index.html
mode: 0644
loop: "{{ vhosts }}"
notify:
- NGINX reload
handlers:
- name: NGINX start
......@@ -15,3 +67,8 @@
state: started
enabled: yes
- name: NGINX reload
service:
name: nginx
state: reloaded
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment