Skip to content

Instantly share code, notes, and snippets.

@Kuchitama
Last active December 17, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kuchitama/5547882 to your computer and use it in GitHub Desktop.
Save Kuchitama/5547882 to your computer and use it in GitHub Desktop.
Sample of Chef recipe to install nginx.
sudo chef-solo -c solo.rb -j ./product.json
%w{g++ libpcre3 libpcre3-dev}.each do |pkg|
package pkg do
action :install
end
end
remote_file "http://nginx.org/download/nginx-1.2.8.tar.gz" do
source "http://nginx.org/download/nginx-1.2.8.tar.gz"
path "/tmp/nginx-1.2.8.tar.gz"
backup false
end
bash "compile_nginx_source" do
cwd ::File.dirname("/tmp/nginx-1.2.8.tar.gz")
code <<-EOH
tar zxf #{::File.basename("/tmp/nginx-1.2.8.tar.gz")} &&
cd nginx-1.2.8 &&
./configure --prefix=/usr/local/nginx-chef &&
make && make install
EOH
#notifies :restart, "service[nginx]"
end
template "nginx.conf" do
path "/usr/local/nginx-chef/conf/nginx.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode 0644
end
#user nobody;
worker_processes <%= node['nginx']['worker_processes'] %>;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main 'remote:$remote_addr\t'
'time:$time_local\t'
'request:$request\t'
'status:$status\t'
'referer:$http_referer\t'
'ua:$http_user_agent';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name <%= node['nginx']['server_name'] %>;
location / {
root html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
{
"run_list" : [
"recipe[hello]",
"recipe[nginx]"
],
"nginx" : {
"worker_processes" : 2,
"server_name" : "prod"
}
}
{
"run_list" : [
"recipe[hello]",
"recipe[nginx]"
],
"nginx" : {
"worker_processes" : 1,
"server_name" : "stage"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment