使用Ansible的Playbook修改nginx配置文件
2018-02-06 14:54
671 查看
目录结构:
文件内容
tasks 目录下的“file.yml”文件,内容如下:![](http://i2.51cto.com/images/blog/201802/06/3e5862e6a995d0c0496d9854a260d824.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
tasks目录下的“main.yml”
![](http://i2.51cto.com/images/blog/201802/06/e8d70dc0358561a7a5a9bf99e468b8dc.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
templates目录下的“nginx.conf.j2”
{% if nginx_use_proxy %} {% for proxy in nginx_proxies %} upstream {{ proxy.name }} { server {{ ansible_eth0.ipv4.address }}:{{ proxy.port }} } {% endfor %} {% endif %} server { listen 80; server_name {{ nginx_server_name }}; access_log off; error_log /dev/null crit; rewrite ^ https://$server_name$request_uri? permanent; } server { listen 443 ssl; server_name {{ nginx_server_name }}; ssl_certificate /etc/nginx/ssl/{{ nginx_ssl_cert_name }}; ssl_certificate_key /etc/nginx/ssl/{{ nginx_ssl_cert_key }}; root {{ nginx_web_root }}; index index.html index.html; {% if nginx_use_auth %} auth_basic "Restricted"; auth_basic_user_file /etc/nginx/{{ project_name }}.htpasswd; {% endif %} {% if nginx_use_proxy %} {% for proxy in nginx_proxies %} location {{ proxy.location }} { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-Url-Scheme $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_redirect off; proxy_pass http://{{ proxy.name }}; } {% endfor %} {% endif %} {% if nginx_server_static %} location / { try_file $uri $uri/ =404 {% endif %} }
var目录下的“main.yml”
--- nginx_server_name: www.test.com nginx_web_root: /opt/test/ nginx_proxies: - name: suspicious location: / port: 2368 - name: suspocoous-api location: /api port: 3000
执行入口文件“nginxconf.yml”
- name: Nginx Proxy Server's Conf Dynamic Create hosts: your IP vars: nginx_use_proxy: true nginx_ssl_cert_name: test.crt nginx_ssl_cert_key: test.key nginx_use_auth: true project_name: suspicious nginx_server_static: true gather_facts: true //收集主机配置信息 roles: - { role: nginxconf } - name: Nginx WebServer's Conf Dynamic Create hosts: your IP vars: nginx_use_proxy: false nginx_ssl_cert_name: test.crt nginx_ssl_cert_key: test.key nginx_use_auth: false project_name: suspicious nginx_server_static: false gather_facts: no roles: - { role: nginxconf }
相关文章推荐
- ansible-playbook管理nginx配置文件
- 使用 sed 修改配置文件
- Delphi、Python使用CGI Apache的配置文件需要修改的事项
- NginX反向代理服务器(Reverse Proxy)——【二】NginX配置文件修改
- WPF学习笔记--使用配置文件修改控件、面板颜色
- 修改web.xml 去掉jetty锁定静态文件的问题 的配置(正点-使用maven,jetty配合)
- 使用PHP对配置文件进行修改
- 修改nginx配置文件,支持php的pathinfo
- 使用XmlDocument 编辑配置文件修改数据库链接
- 服务器文件[置顶] nginx的配置和使用
- ansible的playbook配置及template模板的使用
- 使用apache common configuration读取配置文件或修改配置文件
- nginx运行期间修改配置文件的处理
- PHP经典实例教程(使用正则动态修改配置文件)
- 使用PHP对配置文件进行修改
- python 中使用ConfigParser类修改配置文件
- 在windows下使用PuTTy修改andriod下配置文件
- 利用配置文件修改IIS使用的最大虚拟内存和自动回收时间
- 修改nginx配置文件解决dx2.5下载附件停止不动的问题
- 引自MagicLinux的C代码简单配置文件读取功能(使用需修改)