Commit 99917077

mo khan <mo@mokhan.ca>
2013-07-27 20:35:16
add ssl support to nginx config and other tidy up
1 parent 313ff1e
config/recipes/templates/nginx_unicorn.erb
@@ -4,8 +4,10 @@ upstream unicorn {
 
 server {
   listen 80 default deferred;
-  # server_name cakeside.com
+  # server_name *.cakeside.com
   root <%= current_path %>/public;
+  error_log /var/log/nginx/cakeside.error.log;
+  access_log off;
 
   location ^~ /assets/ {
     gzip_static on;
@@ -25,3 +27,25 @@ server {
   client_max_body_size 4G;
   keepalive_timeout 10;
 }
+
+server {
+  listen       443;
+  # server_name  *.cakeside.com;
+  root         <%= current_path %>/public;
+  ssl on;
+  ssl_certificate             <%= current_path %>/config/staging.crt;
+  ssl_certificate_key         <%= current_path %>/config/staging.key;
+  error_log /var/log/nginx/cakeside.error.log;
+  access_log off;
+
+  try_files $uri/index.html $uri @unicorn;
+  location @unicorn {
+    proxy_set_header X_FORWARDED_PROTO https;
+    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+    proxy_set_header HOST $http_host;
+    proxy_set_header  X-Url-Scheme $scheme;
+    proxy_redirect off;
+    proxy_pass http://unicorn;
+  }
+}
+
config/recipes/nginx.rb
@@ -9,6 +9,10 @@ namespace :nginx do
 
   desc "setup nginx configuration"
   task :setup, roles: :web do
+    run "#{sudo} rm -f /tmp/nginx_conf"
+    run "#{sudo} rm -f /etc/nginx/sites-available/#{application}"
+    run "#{sudo} rm -f /etc/nginx/sites-enabled/#{application}"
+
     template "nginx_unicorn.erb", "/tmp/nginx_conf"
     run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-available/#{application}"
     run "#{sudo} ln -s /etc/nginx/sites-available/#{application} /etc/nginx/sites-enabled/#{application}"
config/deploy.rb
@@ -2,12 +2,12 @@ require 'bundler/capistrano'
 
 load "config/recipes/environments"
 load "config/recipes/base"
-#load "config/recipes/rvm"
-load "config/recipes/rbenv"
 load "config/recipes/nginx"
 load "config/recipes/unicorn"
 load "config/recipes/postgresql"
 load "config/recipes/nodejs"
+#load "config/recipes/rvm"
+load "config/recipes/rbenv"
 load "config/recipes/monit"
 
 set :application, "cakeside"
db/migrate/20120229204756_move_admin_notes_to_comments.rb
@@ -9,8 +9,8 @@ class MoveAdminNotesToComments < ActiveRecord::Migration
     add_index     :active_admin_comments, [:author_type, :author_id]
 
     # Update all the existing comments to the default namespace
-    say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
-    execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
+    #say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
+    #execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
   end
 
   def self.down