ansible部署nginx
Ansible 部署nginx
[root@iZbp1b1xqfqw9z7gs23k2iZ ansible]# tree ../ansible/
../ansible/
├── nginx.yml
└── template
├── index.html
└── nginx.conf.j2
#nginx.yml
---
- hosts: all
gather_facts: no
vars:
package_name: nginx
nginx_port: 80
tasks:
- name: install {{package_name}}
yum: name={{package_name}}
- name: copy {{package_name}} config
template: src=/ansible/template/index.html dest=/usr/share/nginx/html/
- name: copy {{package_name}} config
template: src=/ansible/template/nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify:
- restart nginx
handlers:
- name: restart nginx
service: name=nginx state=restarted
nginx.conf.j2
[root@iZbp1b1xqfqw9z7gs23k2iZ template]# egrep -v "^$|^#" nginx.conf.j2
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 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;
server {
listen {{nginx_port}};
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
提供面试指导、模拟面试、简历项目优化和职业规划等
负责SRE团队,运维架构(DevOps)、微服务流量治理(K8s、Ingress)、稳定性和可测性系统建设(Prometheus、EFK、Loki)

浙公网安备 33010602011771号