该模块已从 James Fryman [email protected] 迁移到 Vox Pupuli。
该模块管理 NGINX 配置。
apt-transport-https
。 include nginx
nginx::resource::server { 'kibana.myhost.com' :
listen_port => 80,
proxy => ' http://localhost:5601 ' ,
}
nginx::resource::server { 'www.puppetlabs.com' :
www_root => ' /var/www/www.puppetlabs.com ' ,
}
nginx::resource::upstream { 'puppet_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.puppetlabs.com' :
proxy => ' http://puppet_rack_app ' ,
}
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 ' ,
}
nginx::resource::upstream 成员的数据类型数组被哈希替换。以下配置不再有效:
nginx::resource::upstream { 'puppet_rack_app' :
members => {
' localhost:3000 ' ,
' localhost:3001 ' ,
' localhost:3002 ' ,
},
}
从现在开始,配置必须如下所示:
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,
},
},
}
默认情况下,创建服务器资源只会创建 HTTP 服务器。要同时创建 HTTPS(启用 SSL)服务器,请在服务器上设置ssl => true
。您将有一个 HTTP 服务器侦听listen_port
(默认端口80
)和一个 HTTPS 服务器侦听ssl_port
(默认端口443
)。两台服务器将具有相同的server_name
和相似的配置。
要仅创建 HTTPS 服务器,请设置ssl => true
并将listen_port
设置为与ssl_port
相同的值。将这些设置为相同的值会禁用 HTTP 服务器。生成的服务器将侦听ssl_port
。
默认情况下,此模块可能会配置已弃用的ssl on
指令。当您下次运行 puppet 时,它将被删除,因为nginx_version
事实现在可用。为了避免这种幂等性问题,您可以手动设置基类的nginx_version
参数。
位置需要特定的设置,具体取决于它们是否应包含在 HTTP、HTTPS 或两者服务器中。
如果您只有 HTTP 服务器(即服务器上的ssl => false
),请确保不要在与服务器关联的任何位置上设置ssl => true
。
如果您在服务器上设置ssl => true
并将listen_port
和ssl_port
设置为不同的值,则您将需要具体的位置设置,因为您将有一个HTTP 服务器侦听listen_port
和一个HTTPS 服务器侦听ssl_port
:
ssl => false
(这是默认值)。ssl => true
,并确保ssl_only => false
(这是ssl_only
的默认值)。ssl => true
和ssl_only => true
。 如果您已在服务器上设置ssl => true
并将listen_port
和ssl_port
设置为相同的值,则您将有一个 HTTPS 服务器侦听ssl_port
。要向此服务器添加位置,请在该位置上设置ssl => true
和ssl_only => true
。
在 Hiera 中定义 nginx 资源。
nginx::nginx_upstreams :
' puppet_rack_app ' :
ensure : present
members :
' localhost:3000 ' :
server : ' localhost '
port : 3000
' localhost:3001 ' :
server : ' localhost '
port : 3001
' localhost:3002 ' :
server : ' localhost '
port : 3002
nginx::nginx_servers :
' www.puppetlabs.com ' :
www_root : ' /var/www/www.puppetlabs.com '
' rack.puppetlabs.com ' :
proxy : ' http://puppet_rack_app '
nginx::nginx_locations :
' static ' :
location : ' ~ "^/static/[0-9a-fA-F]{8}/(.*)$" '
server : www.puppetlabs.com
www_root : /var/www/html
' userContent ' :
location : /userContent
server : www.puppetlabs.com
www_root : /var/www/html
nginx::nginx_mailhosts :
' smtp ' :
auth_http : server2.example/cgi-bin/auth
protocol : smtp
listen_port : 587
ssl_port : 465
starttls : only
nginx::stream : true
nginx::nginx_cfg_prepend :
include :
- ' /etc/nginx/modules-enabled/*.conf '
nginx::nginx_streamhosts :
' syslog ' :
ensure : ' present '
listen_port : 514
listen_options : ' udp '
proxy : ' syslog '
proxy_read_timeout : ' 1 '
proxy_connect_timeout : ' 1 '
raw_append :
- ' error_log off; '
nginx::nginx_upstreams :
' syslog ' :
context : ' stream '
members :
' 10.0.0.1:514 ' :
server : ' 10.0.0.1 '
port : 514
' 10.0.0.2:514 ' :
server : ' 10.0.0.2 '
port : 514
' 10.0.0.3:514 ' :
server : ' 10.0.0.3 '
port : 514
Debian 和 RHEL / CentOS (>6) 的示例配置,从 Phusion 存储库中提取 Nginx 和 Passenger 软件包。请参阅 https://github.com/voxpupuli/puppet-nginx/blob/master/docs/quickstart.md 中的其他注释
class { 'nginx' :
package_source => ' passenger ' ,
http_cfg_append => {
' passenger_root ' => ' /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini ' ,
}
}
这里是 OpenBSD 的示例:
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 ' ,
}
}
包源passenger
将把 Phusion Passenger 存储库添加到 APT 源中。对于每个虚拟主机,您应该指定应使用哪个 ruby。
nginx::resource::server { 'www.puppetlabs.com' :
www_root => ' /var/www/www.puppetlabs.com ' ,
server_cfg_append => {
' passenger_enabled ' => ' on ' ,
' passenger_ruby ' => ' /usr/bin/ruby ' ,
}
}
用于服务 puppet master 的虚拟主机配置:
nginx::resource::server { 'puppet' :
ensure => present ,
server_name => [ ' puppet ' ],
listen_port => 8140,
ssl => true ,
ssl_cert => ' /var/lib/puppet/ssl/certs/example.com.pem ' ,
ssl_key => ' /var/lib/puppet/ssl/private_keys/example.com.pem ' ,
ssl_port => 8140,
server_cfg_append => {
' passenger_enabled ' => ' on ' ,
' passenger_ruby ' => ' /usr/bin/ruby ' ,
' ssl_crl ' => ' /var/lib/puppet/ssl/ca/ca_crl.pem ' ,
' ssl_client_certificate ' => ' /var/lib/puppet/ssl/certs/ca.pem ' ,
' ssl_verify_client ' => ' optional ' ,
' ssl_verify_depth ' => 1,
},
www_root => ' /etc/puppet/rack/public ' ,
use_default_location => false ,
access_log => ' /var/log/nginx/puppet_access.log ' ,
error_log => ' /var/log/nginx/puppet_error.log ' ,
passenger_cgi_param => {
' HTTP_X_CLIENT_DN ' => ' $ssl_client_s_dn ' ,
' HTTP_X_CLIENT_VERIFY ' => ' $ssl_client_verify ' ,
},
}
$full_web_path = ' /var/www '
define web::nginx_ssl_with_redirect (
$backend_port = 9000,
$php = true ,
$proxy = undef ,
$www_root = " ${full_web_path} / ${name} / " ,
$location_cfg_append = undef ,
) {
nginx::resource::server { "${name}.${facts['networking']['domain']}" :
ensure => present ,
www_root => " ${full_web_path} / ${name} / " ,
location_cfg_append => {
' rewrite ' => ' ^ https://$server_name$request_uri? permanent '
}‚,
}
if ! $www_root {
$tmp_www_root = undef
} else {
$tmp_www_root = $www_root
}
nginx::resource::server { "${name}.${facts['networking']['domain']} ${name}" :
ensure => present ,
listen_port => 443,
www_root => $tmp_www_root ,
proxy => $proxy ,
location_cfg_append => $location_cfg_append ,
index_files => [ ' index.php ' ],
ssl => true ,
ssl_cert => ' /path/to/wildcard_mydomain.crt ' ,
ssl_key => ' /path/to/wildcard_mydomain.key ' ,
}
if $php {
nginx::resource::location { "${name}_root" :
ensure => present ,
ssl => true ,
ssl_only => true ,
server => " ${name} .${facts['networking']['domain']} ${name} " ,
www_root => " ${full_web_path} / ${name} / " ,
location => ' ~ . php$ ' ,
index_files => [ ' index.php ' , ' index.html ' , ' index.htm ' ],
proxy => undef ,
fastcgi => " 127.0.0.1: ${backend_port} " ,
fastcgi_script => undef ,
location_cfg_append => {
fastcgi_connect_timeout => ' 3m ' ,
fastcgi_read_timeout => ' 3m ' ,
fastcgi_send_timeout => ' 3m '
}
}
}
}
nginx::resource::location { "some_root" :
ensure => present ,
location => ' /some/url ' ,
fastcgi => " 127.0.0.1:9000 " ,
fastcgi_param => {
' APP_ENV ' => ' local ' ,
},
}
web::nginx_ssl_with_redirect { 'sub-domain-name' :
backend_port => 9001,
}