9

AWS Opsworks でカスタムレイヤーを使用して nginx ウェブサーバーを追加しようとしています。

レイヤーを正常に作成し、GIT 経由でアプリを追加しました (レポにパスワードなし)。コマンドをデプロイすると「成功」しましたが、サーバーに自分のコードが表示されません。

カスタム層では、デプロイ レシピは「deploy::default」のみです。

デプロイを処理するためにカスタム レシピが必要ですか?

また、デプロイの「場所」をどのように設定すればよいですか? Opsworks が常にデプロイされるように見える場所を使用するよりも、自分のドキュメント ルートを選択したいと思います。

これについて何か助けてくれてありがとう。

4

2 に答える 2

13

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 テンプレートを上書きするには、という名前の新しいクックブックを作成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 %>

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"
于 2014-09-08T09:38:34.527 に答える
1

はい、カスタム レイヤー用に独自のカスタム デプロイ レシピを作成する必要があります。デプロイ レシピでは、デプロイ先と、ソフトウェアのデプロイに必要な手順を構成できます。または、Nginx をデプロイする OpsWorks 静的 Web サーバー レイヤーを拡張して、ニーズを満たすことができます。

于 2013-08-12T15:46:23.983 に答える