Last active
December 17, 2015 04:08
-
-
Save Kuchitama/5547882 to your computer and use it in GitHub Desktop.
Sample of Chef recipe to install nginx.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo chef-solo -c solo.rb -j ./product.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"run_list" : [ | |
"recipe[hello]", | |
"recipe[nginx]" | |
], | |
"nginx" : { | |
"worker_processes" : 2, | |
"server_name" : "prod" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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