Рефакторинг: вынес запуск ролей в отдельный файл deploy.yml
- Создан файл roles/deploy.yml с блоком запуска роли nginx - Обновлен molecule/default/site.yml для импорта deploy.yml - Улучшена модульность структуры проекта - Автор: Сергей Антропов
This commit is contained in:
67
roles/nginx/templates/default.conf.j2
Normal file
67
roles/nginx/templates/default.conf.j2
Normal file
@@ -0,0 +1,67 @@
|
||||
# Конфигурация виртуального хоста nginx
|
||||
# Автор: Сергей Антропов
|
||||
# Сайт: https://devops.org.ru
|
||||
# Сгенерировано: {{ ansible_date_time.iso8601 }}
|
||||
|
||||
server {
|
||||
listen {{ nginx_listen_port }};
|
||||
server_name {{ nginx_server_name }};
|
||||
|
||||
# Настройки безопасности
|
||||
{% if nginx_hide_version %}
|
||||
server_tokens off;
|
||||
{% endif %}
|
||||
|
||||
# Корневая директория
|
||||
root {{ nginx_root_dir }};
|
||||
index {{ nginx_index_file }};
|
||||
|
||||
# Настройки логов для этого виртуального хоста
|
||||
access_log {{ nginx_access_log }};
|
||||
error_log {{ nginx_error_log }};
|
||||
|
||||
# Основная локация
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# Настройки для статических файлов
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Настройки безопасности
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Настройки для favicon
|
||||
location = /favicon.ico {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Настройки для robots.txt
|
||||
location = /robots.txt {
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Настройки для health check
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
|
||||
# Настройки для статуса nginx
|
||||
location /nginx_status {
|
||||
stub_status on;
|
||||
access_log off;
|
||||
allow 127.0.0.1;
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
58
roles/nginx/templates/nginx.conf.j2
Normal file
58
roles/nginx/templates/nginx.conf.j2
Normal file
@@ -0,0 +1,58 @@
|
||||
# Основная конфигурация nginx
|
||||
# Автор: Сергей Антропов
|
||||
# Сайт: https://devops.org.ru
|
||||
# Сгенерировано: {{ ansible_date_time.iso8601 }}
|
||||
|
||||
user {{ nginx_user }};
|
||||
worker_processes {{ nginx_worker_processes }};
|
||||
|
||||
error_log {{ nginx_error_log }};
|
||||
pid /run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections {{ nginx_worker_connections }};
|
||||
}
|
||||
|
||||
http {
|
||||
# Основные настройки
|
||||
sendfile {{ nginx_sendfile }};
|
||||
tcp_nopush {{ nginx_tcp_nopush }};
|
||||
tcp_nodelay {{ nginx_tcp_nodelay }};
|
||||
keepalive_timeout {{ nginx_keepalive_timeout }};
|
||||
types_hash_max_size 2048;
|
||||
server_tokens {{ nginx_server_tokens }};
|
||||
|
||||
# Настройки MIME типов
|
||||
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"';
|
||||
|
||||
access_log {{ nginx_access_log }} main;
|
||||
|
||||
# Настройки gzip
|
||||
{% if nginx_gzip %}
|
||||
gzip {{ nginx_gzip_vary }};
|
||||
gzip_min_length {{ nginx_gzip_min_length }};
|
||||
gzip_types
|
||||
{% for gzip_type in nginx_gzip_types %}
|
||||
{{ gzip_type }}{% if not loop.last %} {% endif %}
|
||||
{% endfor %};
|
||||
{% endif %}
|
||||
|
||||
# Настройки безопасности
|
||||
{% if nginx_hide_version %}
|
||||
server_tokens off;
|
||||
{% endif %}
|
||||
|
||||
# Включение конфигураций виртуальных хостов
|
||||
{% if ansible_os_family == "Debian" %}
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
{% elif ansible_os_family == "RedHat" %}
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
{% endif %}
|
||||
}
|
||||
Reference in New Issue
Block a user