百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

puppet-nginx

> DevOps
开源

用于在各种 UNIX 系统上管理 NGINX 的 Puppet 模块

469 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于在各种 UNIX 系统上管理 NGINX 的 Puppet 模块

NGINX module for Puppet

This module was migrated from James Fryman to Vox Pupuli.

INSTALLING OR UPGRADING

This module manages NGINX configuration.

Requirements

  • Puppet 4.6.1 or later. Puppet 3 was supported up until release 0.6.0.
  • apt is now a soft dependency. If your system uses apt, you'll need to configure an appropriate version of the apt module. Version 9.2.0 or higher is recommended because of supporting "modern keyrings".

Additional Documentation

  • A Quickstart Guide to the NGINX Puppet Module

Install and bootstrap an NGINX instance

puppet
include nginx

A simple reverse proxy

puppet
nginx::resource::server { 'kibana.myhost.com':
  listen_port => 80,
  proxy       => 'http://localhost:5601',
}

A virtual host with static content

puppet
nginx::resource::server { 'voxpupuli.org':
  www_root => '/var/www/voxpupuli.org',
}

A more complex proxy example

puppet
nginx::resource::upstream { 'openvox_rack_app':
  members => {
    'localhost:3000' => {
      server => 'localhost',
      port   => 3000,
      weight => 1,
    },
    'localhost:3001' => {
      server => 'localhost',
      port   => 3001,
      weight => 1,
    },
    'localhost:3002' => {
      server => 'localhost',
      port   => 3002,
      weight => 2,
      },
  },
}

nginx::resource::server { 'rack.voxpupuli.org':
  proxy => 'http://openvox_rack_app',
}

Add a smtp proxy

puppet
class { 'nginx':
  mail => true,
}

nginx::resource::mailhost { 'domain1.example':
  auth_http       => 'server2.example/cgi-bin/auth',
  protocol        => 'smtp',
  listen_port     => 587,
  ssl_port        => 465,
  starttls        => 'only',
  xclient         => 'off',
  proxy_protocol  => 'off',
  proxy_smtp_auth => 'off',
  ssl             => true,
  ssl_cert        => '/tmp/server.crt',
  ssl_key         => '/tmp/server.pem',
}

Convert upstream members from Array to Hash

The datatype Array for members of a nginx::resource::upstream is replaced by a Hash. The following configuration is no longer valid:

puppet
nginx::resource::upstream { 'puppet_rack_app':
  members => {
    'localhost:3000',
    'localhost:3001',
    'localhost:3002',
  },
}

From now on, the configuration must look like this:

puppet
nginx::resource::upstream { 'puppet_rack_app':
  members => {
    'localhost:3000' => {
      server => 'localhost',
      port   => 3000,
    },
    'localhost:3001' => {
      server => 'localhost',
      port   => 3001,
    },
    'localhost:3002' => {
      server => 'localhost',
      port   => 3002,
    },
  },
}

SSL configuration

By default, creating a server resource will only create a HTTP server. To also create a HTTPS (SSL-enabled) server, set ssl => true on the server. You will have a HTTP server listening on listen_port (port 80 by default) and a HTTPS server listening on ssl_port (port 443 by default). Both servers will have the same server_name and a similar configuration.

To create only a HTTPS server, set ssl => true and also set listen_port to the same value as ssl_port. Setting these to the same value disables the HTTP server. The resulting server will be listening on ssl_port.

Idempotency with nginx 1.15.0 and later

By default, this module might configure the deprecated ssl on directive. When you next run puppet, this will be removed since the nginx_version fact will now be available. To avoid this idempotency issue, you can manually set the base class's nginx_version parameter.

Locations

Locations require specific settings depending on whether they should be included in the HTTP, HTTPS or both servers.

HTTP only server (default)

If you only have a HTTP server (i.e. ssl => false on the server) make sure you don't set ssl => true on any location you associate with the server.

HTTP and HTTPS server

If you set ssl => true and also set listen_port and ssl_port to different values on the server you will need to be specific with the location settings since you will have a HTTP server listening on listen_port and a HTTPS server listening on ssl_port:

  • To add a location to only the HTTP server, set ssl => false on the location (this is the default).
  • To add a location to both the HTTP and HTTPS server, set ssl => true on the location, and ensure ssl_only => false (which is the default value for ssl_only).
  • To add a location only to the HTTPS server, set both ssl => true and ssl_only => true on the location.

HTTPS only server

If you have set ssl => true and also set listen_port and ssl_port to the same value on the server, you will have a single HTTPS server listening on ssl_port. To add a location to this server set ssl => true and ssl_only => true on the location.

Hiera Support

Defining nginx resources in Hiera.

…

A stream syslog UDP proxy

…

Nginx with precompiled Passenger

Example configuration for Debian and RHEL / CentOS (>6), pulling the Nginx and Passenger packages from the Phusion repo. See additional notes in https://github.com/voxpupuli/puppet-nginx/blob/master/docs/quickstart.md

puppet
class { 'nginx':
  package_source  => 'passenger',
  http_cfg_append => {
    'passenger_root' => '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini',
  }
}

Here the example for OpenBSD:

puppet
class { 'nginx':
  package_flavor => 'passenger',
  service_flags  => '-u'
  http_cfg_append => {
    passenger_root          => '/usr/local/lib/ruby/gems/2.1/gems/passenger-4.0.44',
    passenger_ruby          =>  '/usr/local/bin/ruby21',
    passenger_max_pool_size => '15',
  }
}

Package source passenger will add Phusion Passenger repository to APT sources. For each virtual host you should specify which ruby should be used.

puppet
nginx::resource::server { 'voxpupuli.org':
  www_root          => '/var/www/voxpupuli.org',
  server_cfg_append => {
    'passenger_enabled' => 'on',
    'passenger_ruby'    => '/usr/bin/ruby',
  }
}

Puppet master served by Nginx and Passenger

Virtual host config for serving puppet master:

…

Example puppet class calling nginx::server with HTTPS FastCGI and redirection of HTTP

…

Add custom fastcgi_params

puppet
nginx::resource::location { "some_root":
  ensure         => present,
  location       => '/some/url',
  fastcgi        => "127.0.0.1:9000",
  fastcgi_param  => {
    'APP_ENV' => 'local',
  },
}

Call class web::nginx_ssl_with_redirect

puppet
web::nginx_ssl_with_redirect { 'sub-domain-name':
    backend_port => 9001,
  }

Issues· 106 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyarchlinux-puppet-modulebsd-puppet-modulecentos-puppet-moduledebian-puppet-module

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理