9

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

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

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

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

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

感谢您对此的任何帮助。

4

2 回答 2

13

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

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

部署.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 模板,只需创建一个名为的新说明书nginxsite.erbtemplates/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 %>

我的 Berksfile(作曲家)

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

cookbook 'composer', '~> 1.0.4'

我在部署 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"
于 2014-09-08T09:38:34.527 回答
1

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

于 2013-08-12T15:46:23.983 回答