ginsys.nginx

nginx

这个角色是从 https://github.com/bennojoy/nginx 分叉而来的。 它实现了一种不同的参数定义“API”。

这个角色安装和配置 nginx 网络服务器。用户可以指定任何他们希望应用于网站的 http 配置参数。可以添加任意数量的网站,并按自己的选择进行配置。

要求

此角色需要 Ansible 1.4 或更高版本,平台要求在元数据文件中列出。

角色变量

可以传递给这个角色的变量及其简要描述如下:

# 允许的最大客户端数量
nginx_max_clients: 512

# http 参数的哈希。注意,这里可以添加任何有效的 nginx http 参数。
# (有关详细信息,请参见 nginx 文档。)
nginx_http_params:
  sendfile: "on"
  tcp_nopush: "on"
  tcp_nodelay: "on"
  keepalive_timeout: "65"
  access_log: "/var/log/nginx/access.log"
  error_log: "/var/log/nginx/error.log"

# 定义 nginx 服务器的哈希列表,
# 类似于 http 参数。任何有效的服务器参数
# 都可以在这里定义。
nginx_sites:
 - server:
      file_name: foo
      listen: 8080
      server_name: localhost
      root: "/tmp/site1"
   location:
    - name: /
      try_files: "$uri $uri/ /index.html"
    - name: /images/
      try_files: "$uri $uri/ /index.html"
 - server:
      file_name: bar
      listen: 9090
      server_name: ansible
      root: "/tmp/site2"
   location:
    - name: /
      try_files: "$uri $uri/ /index.html"
    - name: /images/
      try_files: "$uri $uri/ /index.html"

示例

  1. 安装 nginx,使用自定义的 HTTP 指令,但未配置网站:

    • hosts: all roles:
      • {role: nginx, nginx_http_params: { sendfile: "on", access_log: "/var/log/nginx/access.log"}, nginx_sites: none }
  2. 安装 nginx,使用与前一个示例不同的 HTTP 指令,但未配置网站。

    • hosts: all roles:
      • {role: nginx, nginx_http_params: { tcp_nodelay: "on", error_log: "/var/log/nginx/error.log"}, nginx_sites: none }

注意:请确保传递的 HTTP 指令是有效的,因为此角色不会检查指令的有效性。有关详细信息,请参见 nginx 文档。

  1. 安装 nginx 并将网站添加到配置中。

    • hosts: all

      roles:

      • role: nginx, nginx_http_params: sendfile: "on" access_log: "/var/log/nginx/access.log" nginx_sites:
        • server: file_name: bar listen: 8080 location:
          • name: "/" try_files: "$uri $uri/ /index.html"
          • name: /images/ try_files: "$uri $uri/ /index.html"

注意:每个添加的网站用哈希列表表示,生成的配置会填充到 /etc/nginx/sites-available/中,并在 /etc/nginx/sites-enabled/ 中有相应的符号链接。

特定网站配置的文件名在哈希中用“file_name”键指定,任何有效的服务器指令可以添加到哈希中。 对于位置指令,添加“location”键后缀一个唯一的数字,位置的值是哈希,请确保它们是有效的位置指令。

  1. 安装 Nginx 并添加两个网站(不同方法)


    • hosts: all roles:
      • role: nginx nginx_http_params: sendfile: "on" access_log: "/var/log/nginx/access.log" nginx_sites:
        • server: file_name: foo listen: 8080 server_name: localhost root: "/tmp/site1" location:
          • name: / try_files: "$uri $uri/ /index.html"
          • name: /images/ try_files: "$uri $uri/ /index.html"
        • server: file_name: bar listen: 9090 server_name: ansible root: "/tmp/site2" location:
          • name: / try_files: "$uri $uri/ /index.html"
          • name: /images/ try_files: "$uri $uri/ /index.html"

依赖

许可证

BSD

作者信息

原角色作者: Benno Joy Ginsys 分叉作者: Serge van Ginderachter serge@vanginderachter.be

关于项目

This ansible role manages installation and configuration of nginx. It can both configure general options, as well as virtual hosts. This role is a fork of https://github.com/bennojoy/nginx and implements a different API for configuring locations within a

安装
ansible-galaxy install ginsys.nginx
许可证
Unknown
下载
114
拥有者
automate all things!