該模組已從 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,
}