|
# 编辑temp2.pp的配置文件如下:
[root@centos7 manifests]# vim temp2.pp
class nginx {
package{'nginx':
ensure => installed,
provider => 'rpm',
source => '/root/nginx/nginx-1.10.0-1.el7.ngx.x86_64.rpm',
}
service{'nginx':
ensure => running,
enable => false,
require => Package['nginx'],
}
}
class nginx::web inherits nginx {
file{'ngx-web.conf':
path => '/etc/nginx/conf.d/ngx-web.conf',
ensure => file,
require => Package['nginx'],
source => '/root/manifests/nginx/ngx-web.conf',
}
file{'nginx.conf':
path => '/etc/nginx/nginx.conf',
ensure => file,
content => template('/root/manifests/nginx/nginx.conf.erb'), # 使用模板文件
require => Package['nginx'],
}
Service['nginx'] {
subscribe => [ File['ngx-web.conf'],File['nginx.conf'] ],
}
}
include nginx::web
----------------------------------------------------------------------------------------
# 编辑nginx.conf的模板文件
[root@centos7 manifests]# cat nginx/nginx.conf.erb
user nginx;
worker_processes <%= @processorcount %>; # 进程数使用内置变量替换
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
} |
|
|