Tôi đã viết một công thức đơn giản sử dụng công thức ngụy trang Opsworks để triển khai ứng dụng hoàn toàn tự động. Nó kiểm tra từ cấu hình SCM của bạn, tạo ra một vin nginx mới và tải lại nginx nếu cần thiết.
Thêm công thức này để cấu hình triển khai trong lớp:
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
Để ghi đè lên mẫu nginx vhost, chỉ cần tạo một sách dạy nấu ăn mới gọi là nginx
và thêm một tập tin site.erb
trong templates/default
. Opsworks sẽ tự động sử dụng mẫu này sau đó.
site.erb của tôi trông như thế này
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 (đối với nhà soạn nhạc)
source "https://supermarket.getchef.com"
cookbook 'composer', '~> 1.0.4'
metadata.rb của tôi trong sách dạy nấu ăn cho triển khai appserver :: triển khai recipe
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"
Nguồn
2014-09-08 09:38:34
Nó thực sự hút khi bạn trả lời một câu hỏi rất chi tiết nhưng câu trả lời của bạn không được chấp nhận hoặc bạn chỉ đơn giản là nói 'cảm ơn'. Vâng .. Cảm ơn bạn thay mặt cho những người dùng SOF khác. – scaryguy