首页 > 代码库 > puppet管理nginx
puppet管理nginx
一:介绍
puppet管理nginx主机,将nginx主机加入到puppet中,实现自动安装、配置、和启动服务
二:nginx模块结构
[root@master modules]# tree /etc/puppet/modules/nginx/ /etc/puppet/modules/nginx/ ├── files ├── manifests │ ├── conf.pp │ ├── init.pp │ └── install.pp └── templates ├── nginx.conf.erb └── vhost.erb |
三:配置解释
install.pp为安装nginx的配置文件
[root@master manifests]# cat install.pp class nginx::install { package {"nginx": ensure => present, } } |
conf.pp为配置nginx的配置文件
[root@master manifests]# cat conf.pp class nginx::conf { define nginx::vhost($port,$hostname,$rootdir,$filename=$title){ file {"/etc/nginx/conf.d": ensure => directory, owner => "root", group => "root", mode => "744", recurse => true, require => Class["nginx::install"], } file {"$filename": owner => "root", group => "root", mode => "644", path => "/etc/nginx/conf.d/${filename}", content => template("nginx/vhost.erb"), require => File["/etc/nginx/conf.d"], } } nginx::vhost{"www.puppet.com.conf": port => "80", hostname => "www.puppet.com", rootdir => "/var/www/puppet", } } |
init.pp为nginx模块的入口文件
[root@master manifests]# cat init.pp class nginx { include nginx::install,nginx::conf } |
templates下面为nginx配置文件模板:
[root@master templates]# cat vhost.erb server { listen <%= port %>; server_name <%= hostname %>; root <%= rootdir %>; index index.php; location ~ .*\.php { proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_headers_hash_max_size 512; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; } location ~ \.(css|js)?$ { expires 2h; } location ~ .*\.(mp3|jpg|jpeg|rar|png|zip|wmv|rm|doc|ppt|gif|bmp|xls|pdf|swf)$ { expires 5d; } } |
本文出自 “人要有梦想,万一实现了呢” 博客,请务必保留此出处http://yangke.blog.51cto.com/9530509/1568500
puppet管理nginx
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。