From 2b7f19376e8c4d03a380126b579eb8d2f1440db8 Mon Sep 17 00:00:00 2001 From: Matt Moriarity Date: Fri, 3 Aug 2007 23:20:48 -0400 Subject: [PATCH] Working on deployment. Added nginx support. --- config/deploy/local.rb | 2 + config/deploy/ubuntu.rb | 90 ++++++++++++++++++++++++++++++++ config/nginx.conf | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 config/deploy/local.rb create mode 100644 config/deploy/ubuntu.rb create mode 100644 config/nginx.conf diff --git a/config/deploy/local.rb b/config/deploy/local.rb new file mode 100644 index 0000000..f5e5d28 --- /dev/null +++ b/config/deploy/local.rb @@ -0,0 +1,2 @@ +set :local_scm_command, "git" +set :local_git_dir, "/Users/mattmoriarity/Archive/Programming/Ruby/lyrix/.git" \ No newline at end of file diff --git a/config/deploy/ubuntu.rb b/config/deploy/ubuntu.rb new file mode 100644 index 0000000..07eb7f0 --- /dev/null +++ b/config/deploy/ubuntu.rb @@ -0,0 +1,90 @@ +require 'deprec/recipes' + +# ============================================================================= +# ROLES +# ============================================================================= +# You can define any number of roles, each of which contains any number of +# machines. Roles might include such things as :web, or :app, or :db, defining +# what the purpose of each machine is. You can also specify options that can +# be used to single out a specific subset of boxes in a particular role, like +# :primary => true. + +set :domain, "ubuntu" +role :web, domain +role :app, domain +role :db, domain, :primary => true +role :scm, domain + +# ============================================================================= +# REQUIRED VARIABLES +# ============================================================================= +# You must always specify the application and repository for every recipe. The +# repository must be the URL of the repository you want this recipe to +# correspond to. The deploy_to path must be the path on each machine that will +# form the root of the application path. + +set :application, "lyrix" +set :deploy_to, "/var/www/apps/#{application}" + +# XXX we may not need this - it doesn't work on windows +# XXX set :user, ENV['USER'] +set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk" +set :rails_env, "production" + +# Automatically symlink these directories from current/public to shared/public. +# set :app_symlinks, %w{photo, document, asset} + +# ============================================================================= +# SPECIAL OPTIONS +# ============================================================================= +# These options allow you to tweak deprec behaviour + +# If you do not keep database.yml in source control, set this to false. +# After new code is deployed, deprec will symlink current/config/database.yml +# to shared/config/database.yml +# +# You can generate shared/config/database.yml with 'cap generate_database_yml' +# +# set :database_yml_in_scm, true + +# ============================================================================= +# APACHE OPTIONS +# ============================================================================= +set :apache_server_name, domain +# set :apache_server_aliases, %w{alias1 alias2} +# set :apache_default_vhost, true # force use of apache_default_vhost_config +# set :apache_default_vhost_conf, "/usr/local/apache2/conf/default.conf" +# set :apache_conf, "/usr/local/apache2/conf/apps/#{application}.conf" +# set :apache_ctl, "/etc/init.d/httpd" +# set :apache_proxy_port, 8000 +# set :apache_proxy_servers, 2 +# set :apache_proxy_address, "127.0.0.1" +# set :apache_ssl_enabled, false +# set :apache_ssl_ip, "127.0.0.1" +# set :apache_ssl_forward_all, false +# set :apache_ssl_chainfile, false + + +# ============================================================================= +# MONGREL OPTIONS +# ============================================================================= +# set :mongrel_servers, apache_proxy_servers +# set :mongrel_port, apache_proxy_port +set :mongrel_address, apache_proxy_address +# set :mongrel_environment, "production" +# set :mongrel_config, "/etc/mongrel_cluster/#{application}.conf" +# set :mongrel_user_prefix, 'mongrel_' +# set :mongrel_user, mongrel_user_prefix + application +# set :mongrel_group_prefix, 'app_' +# set :mongrel_group, mongrel_group_prefix + application + +# ============================================================================= +# MYSQL OPTIONS +# ============================================================================= + + +# ============================================================================= +# SSH OPTIONS +# ============================================================================= +# ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key) +# ssh_options[:port] = 25 diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..5cbc519 --- /dev/null +++ b/config/nginx.conf @@ -0,0 +1,133 @@ +## http://brainspl.at/nginx.conf.txt + +#user and group to run as +user www-data; + +# number of nginx workers +worker_processes 2; + +# pid of nginx master process +pid /var/run/nginx.pid; + +# Number of worker connections. 1024 is a good default +events { + worker_connections 1024; +} + +# start the http module where we config http access. +http { + # pull in mime-types. You can break out your config + # into as many include's as you want to make it cleaner + include /etc/nginx/mime.types; + + # set a default type for the rare situation that + # nothing matches from the mimie-type include + default_type application/octet-stream; + + # configure log format + log_format main '$remote_addr - $remote_user [$time_local] $status ' + '"$request" $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "http_x_forwarded_for"'; + + # main access log + access_log /var/log/nginx/access.log main; + + # main error log + error_log /var/log/nginx/error.log debug; + #error_log logs/error.log debug_http; + + # no sendfile on OSX + sendfile on; + + # These are good default values. + #tcp_nopush on; + tcp_nodelay off; + # output compression saves bandwidth + gzip on; + gzip_http_version 1.0; + gzip_comp_level 2; + gzip_proxied any; + gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml + application/xml+rss text/javascript; + + # this is where you define your mongrel clusters. + # you need one of these blocks for each cluster + # and each one needs its own name to refer to it later. + upstream lyrix { + server 127.0.0.1:8000; + server 127.0.0.1:8001; + } + + # the server directive is nginx's virtual host directive. + server { + # port to listen on. Can also be set to an IP:PORT + listen 80; + + # sets the domain[s] that this vhost server requests for + server_name lyrix.ubuntu; + + # doc root + root /var/www/apps/lyrix/current/public; + + # vhost specific access log + access_log logs/lyrix.access.log main; + + #Set the max size for file uploads to 50Mb + client_max_body_size 50M; + + # this rewrites all the requests to the maintenance.html + # page if it exists in the doc root. This is for capistrano's + # disable web task + if (-f $document_root/maintenance.html){ + rewrite ^(.*)$ /maintenance.html last; + break; + } + + if ($host ~* "www") { + rewrite ^(.*)$ http://lyrix.ubuntu$1 redirect; + break; + } + + location / { + + + # needed to forward user's IP address to rails + proxy_set_header X-Real-IP $remote_addr; + + # needed for HTTPS + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect false; + proxy_max_temp_file_size 0; + + # check for index.html for directory index + # if its there on the filesystem then rewite + # the url to add /index.html to the end of it + # and then break to send it to the next config rules. + if (-f $request_filename/index.html) { + rewrite (.*) $1/index.html break; + } + + # this is the meat of the rails page caching config + # it adds .html to the end of the url and then checks + # the filesystem for that file. If it exists, then we + # rewite the url to have explicit .html on the end + # and then send it on its way to the next config rule. + # if there is no file on the fs then it sets all the + # necessary headers and proxies to our upstream mongrels + if (-f $request_filename.html) { + rewrite (.*) $1.html break; + } + + if (!-f $request_filename) { + proxy_pass http://lyrix; + break; + } + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + } +} -- 2.11.4.GIT