I am currently using the following options in my Rails app to enable HTTPS with WEBrick:
{
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("certificates/https/key.pem").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("certificates/https/cert.pem").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
}
How would I go about specifying an intermediate certificate?
I managed to find an answer after an extra hour of googling for keywords. Here is the option to define an intermediate certificate:
:SSLExtraChainCert => [
OpenSSL::X509::Certificate.new(
File.open("certificates/intermediate.crt").read)]
Note that the option requires an Array object, allowing to you include multiple certificates if needed.
If you are using rails 3, then modify the script/rails file as
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rubygems' # if ruby 1.8.7
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(
File.open("/key/vhost1.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(
File.open("/crt/vhost1.crt").read),
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
})
end
end
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
The above code was modified from the example in Configuring WEBrick to use SSL in Rails 3. This worked for me.
Related
I currently have an application using paperclip that allows users to upload their creatives. This has worked flawless thus far when it comes to a user uploading an image file. We have since tested to upload a .mov file and I get this error:
Creative Paperclip::Errors::NotIdentifiedByImageMagickError
The weird thing, this error is only generated on Heroku. I can upload .mov files just fine on my local host.
My Current Gem Setup:
paperclip (3.4.1, 3.4.0)
paperclip-aws (1.6.7, 1.6.6)
paperclip-ffmpeg (0.10.2)
cocaine (0.5.1, 0.4.2)
Event.rb
has_attached_file :creative,
:processors => [:ffmpeg],
:styles => {
:thumb => [:geometry => "250x150", :format => 'png'],
:custcreative => [:geometry => "275x75", :format => 'png'],
:creativepreview => ["275x195",:png]
},
:url => "***",
:path => "***",
:s3_domain_url => "***",
:storage => :s3,
:s3_credentials => Rails.root.join("config/s3.yml"),
:bucket => '***',
:s3_permissions => :public_read,
:s3_protocol => "http",
:convert_options => { :all => "-auto-orient" },
:encode => 'utf8'
Spending hours trying to figure out why this works locally but throwing error on Heroku.
I even tried removing the :style setting, but still did not work.
TIA
EDIT
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/MidPen20130413-2-1mzetus.mov[0]'
Well, here is the answer in case any other newbies like us come across the same problem. The issue is with the geometry method that is being used for image cropping. The way it is suggested in railscasts assumes the file is in a local system and that needs to be changed.
OLD METHOD:
def avatar_geometry(style = :original)
#geometry ||= {}
#geometry[style] ||= Paperclip::Geometry.from_file(avatar.path(style))
end
NEW METHOD
def avatar_geometry(style = :original)
#geometry ||= {}
avatar_path = (avatar.options[:storage] == :s3) ? avatar.url(style) : avatar.path(style)
#geometry[style] ||= Paperclip::Geometry.from_file(avatar_path)
end
I am working with Paperclip and AWS and can successfully get the upload to work on my local host. The problem I run into is when I upload the app to Heroku I get:
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.)
Locations.rb
has_attached_file :photo,
:styles => { :thumb => "150x150#", :medium => "200x200#", :small => "50x50"},
:path => ":attachment/:id/:style.:extension",
:s3_domain_url => "adsimgstore.s3.amazonaws.com",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:bucket => 'adsimgstore',
:s3_permissions => :public_read,
:convert_options => { :all => "-auto-orient" }
s3 initialize
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "adsimgstore"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
I have followed the Heroku tutorial https://devcenter.heroku.com/articles/s3 and added all keys
Any suggestions?
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.):
2012-05-01T18:01:02+00:00 app[web.1]:
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:76:in `block in update'
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:75:in `update'
2012-05-01T18:01:02+00:00 app[web.1]:
check if your environment variables match
if you followed the heroku tutorial your environment variables would be AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
run heroku config to check your env variables.
no :bucket in Credentials
You put the :bucket option in the S3_CREDENTIALS-hash in the initializers/s3.rb file. the bucket-option doesn't belong here - you already set it in the has_attached_file method.
I built an application with Rails 3 and I made a simple contact us page to send mail through my SMTP server.
The problem is my app can send mail when I run it in my local host (my pc), but it doesn't work when I run the app in the hosted server (hostgator).
The funny stuff is that the smtp server is the same!
This is the config in my localhost(and it works!):
config/environments/developer.rb
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "mail.mydomain.org",
:port => 26,
:domain => "app.mydomain.org",
:user_name => "register#app.mydomain.org",
:password => "********",
:authentication => "plain",
:enable_starttls_auto => false
}
The url for my host server is app.mydomain.org, so in the hosted app I changed only this:
config/environments/development.rb
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'mydomain.org' }
...
In the host server, just for now I run the app with WEBrick in development mode.
And I get a timeout error:
....
Timeout::Error (execution expired):
app/controllers/contact_us_controller.rb:13:in `create'
...
Am I missing somenthing??
EDIT & SOLVED:
Hostgator support staff have just find out the cause of this issue.
In the ActionMailer setup, the :address has to be localhost, and not mail.mydomain.org. So the ActionMailer would be:
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 26,
:domain => "app.mydomain.org",
:user_name => "register#app.mydomain.org",
:password => "********",
:authentication => "plain",
:enable_starttls_auto => false
}
I think you mean development.rb, not developer.rb. This setting only runs in development and assuming you've set RAILS_ENV as production on the server, it will be production.rb, not development.rb, is going to be processed.
If the server is the same on both, you could move this to application.rb (or a script in config/initializers). You might want a different setup for production though, so that it's pointing to localhost. That may also fix the problem here, in case there's some DNS issue or server config preventing the outgoing SMTP request.
I've set up the Resque-web interface to work with my rails 3 app but it doesn't work in either development or production environments. My set up is as follows, and going to localhost:3000/resque just gives me the 404 page I've set up.
Routes.rb
mount Resque::Server.new, :at => "/resque"
Resque initializer
require 'resque'
require 'resque/server'
if Rails.env.development?
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => 'localhost', :port => '6379')
else
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end
Dir["#{Rails.root.to_s}/app/jobs/*.rb"].each { |file| require file }
Resque::Server.class_eval do
use Rack::Auth::Basic do |email, password|
user = User.authenticate( 'foo#bar.co.za', 'password' )
user && user.admin?
end
end
My routes.rb file has:
require "resque/server"
MyApp::Application.routes.draw do
# routes and stuff
mount Resque::Server.new, :at => "/resque"
root :to => 'page#welcome'
end
Maybe you forgot the require inside the routes.rb file?
I do not have a resque initializer, so I don't know if that is causing your problem or not.
I have a route that matches '/:name' to a 'model#index' route must be confusing Resque so I've just mounted it to '/resque/web'
Hi I just migrated to heroku cedar stack. app is Rails 3, ive been using paperclip on s3 just fine previously. my gemfile has:
gem 'paperclip', '2.3.11'
gem 'aws-s3', '0.6.2'
my model file has:
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS
Ive created a new file to store S3_CREDENTIALS,:
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "app_content"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
... with s3.yml containing my keys for local dev, and the keys set in heroku config:
S3_KEY => AK...
S3_SECRET => FFE...
as mentioned, everything works just fine on local. i can even see the existing avatars from before. just, when i try to upload anything new, i get no errors in heroku logs, but the picture never uploads.
ive went thru many stackoverflow issues, but none matching this. can anyone help??
Try adding the following to your model
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:url => "/assets/avatar/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/avatar/:id/:style/:basename.:extension"
The missing path / default path might be causing an issue.
turns out i needed to upgrade my paperclip gem to '2.4.5'
i did this in my Gemfile, then bundle update, and it worked!