繁体   English   中英

AWS Opsworks自定义层部署

[英]AWS Opsworks Custom Layer Deployment

我正在尝试在AWS Opsworks中使用自定义图层来添加nginx网络服务器。

我已成功创建了图层,我通过GIT添加了我的应用程序(repo上没有密码),但是当我部署命令时“成功”但我在服务器上看不到任何代码。

在自定义层中,唯一的部署配方是“deploy :: default”。

我是否需要自定义配方来处理部署?

另外,如何配置部署的“位置”? 我更喜欢选择我的文档根目录,而不是使用Opsworks似乎总是部署到的位置。

感谢您对此的任何帮助。

我写了一个简单的配方,它使用Opsworks nginx配方完全自动部署应用程序。 它从您配置的SCM中检出,创建一个新的nginx vhost,并在需要时重新加载nginx。

将此配方添加到层中的deploy配置:

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的新手册,并在templates/default添加一个文件site.erb 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 %>

我的Berksfile(作曲家)

source "https://supermarket.getchef.com"

cookbook 'composer', '~> 1.0.4'

我的metadata.rb在部署appserver :: deploy配方的cookbook中

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"

是的,您需要为自定义层编写自己的自定义部署配方。 部署配方可以配置部署的位置以及部署软件所需的任何步骤。 或者,您可以扩展部署Nginx的OpsWorks静态Web服务器层,以满足您的需求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM