Opsworks nginx レシピを使用してアプリを完全に自動的にデプロイする簡単なレシピを作成しました。構成された SCM からチェックアウトし、新しい nginx vhost を作成し、必要に応じて nginx をリロードします。
このレシピをレイヤーのデプロイ構成に追加します。
deploy.rb
include_recipe "deploy"
include_recipe "php5"
node[:deploy].each do |application, deploy|
Chef::Log.info("Deploying application #{application} on #{node[:opsworks][:instance][:hostname]}")
if deploy[:application_type] != 'php'
Chef::Log.warn("Skipping deploy::web application #{application} as it is not a PHP app")
next
end
opsworks_deploy_dir do
user deploy[:user]
group deploy[:group]
path deploy[:deploy_to]
end
opsworks_deploy do
app application
deploy_data deploy
end
nginx_web_app application do
application deploy
end
Chef::Log.info("Running composer update on #{deploy[:deploy_to]}")
composer_update do
path deploy[:deploy_to]}
end
end
nginx vhost テンプレートを上書きするには、という名前の新しいクックブックを作成nginx
しsite.erb
、templates/default
. Opsworks は、このテンプレートを自動的に使用します。
私のsite.erbは次のようになります
server {
listen 80;
server_name <%= @application[:domains].join(" ") %> <%= node[:hostname] %>;
access_log <%= node[:nginx][:log_dir] %>/<%= @application[:domains].first %>.access.log;
root <%= @application[:absolute_document_root] %>;
location / {
try_files $uri /index.php?url=$uri&$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Block all svn access
if ($request_uri ~* ^.*\.svn.*$) {
return 404;
}
# Block all git access
if ($request_uri ~* ^.*\.git.*$) {
return 404;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
<% if @application[:ssl_support] %>
server {
listen 443;
server_name <%= @application[:domains].join(" ") %> <%= node[:hostname] %>;
access_log <%= node[:nginx][:log_dir] %>/<%= @application[:domains].first %>-ssl.access.log;
ssl on;
ssl_certificate <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.crt;
ssl_certificate_key <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.key;
<% if @application[:ssl_certificate_ca] -%>
ssl_client_certificate <%= node[:nginx][:dir] %>/ssl/<%= @application[:domains].first %>.ca;
<% end -%>
location / {
try_files $uri /index.php?url=$uri&$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Block all svn access
if ($request_uri ~* ^.*\.svn.*$) {
return 404;
}
# Block all git access
if ($request_uri ~* ^.*\.git.*$) {
return 404;
}
}
<% end %>
My Berksfile (作曲家用)
source "https://supermarket.getchef.com"
cookbook 'composer', '~> 1.0.4'
deploy appserver::deploy レシピのクックブックの metadata.rb
name 'appserver'
maintainer 'Michel Feldheim'
description 'Setting up the appserver environment'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
depends "nginx"
depends "php5"