Rails SSL 混淆了内容
Rails SSL messed up content
我刚刚使用 Rubber & Capist运行o 在我的 Rails 应用程序上完成了 SSL 证书的安装。现在,我的应用程序没有显示任何样式,图像很大,javascript 也不再工作了。
此应用程序之前部署在 AWS 中,只能使用 HTTP,因此我对 Rubber 部署配置文件进行了更改,运行 cap deploy
,现在这是结果。
它应该是这样的:
这是开启 SSL 后的样子:
以下是我修改的文件:
rubber/role/nginx/unicorn_nginx.conf
<%
@path = "/etc/nginx/rubber/unicorn_nginx.conf"
%>
upstream unicorn_server {
# This is the socket we configured in unicorn.rb
server unix:/var/run/unicorn.sock
fail_timeout=0;
}
server {
listen 80;
<% if Rubber.env == 'production' %>
# SSL
listen 443 ssl;
ssl_certificate /etc/ssl/mycert.crt;
ssl_certificate_key /etc/ssl/private/server.key;
<% end %>
<% if Rubber.env == 'staging' %>
# SSL Cap
listen 443 ssl;
ssl_certificate /etc/ssl/mycert.crt;
ssl_certificate_key /etc/ssl/server.key;
<% end %>
client_max_body_size 4G;
server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;
keepalive_timeout 5;
# Location of our static files
root <%= Rubber.root + "/public" %>;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
<% if Rubber.env == 'production' || Rubber.env == 'staging' %>
proxy_set_header X-Forwarded-Proto https;
<% end %>
proxy_redirect off;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://unicorn_server;
break;
}
}
# 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/system/maintenance.html)
{
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
error_page 500 502 503 504 /500.html;
location = /500.html
{
root <%= Rubber.root + "/public" %>;
}
error_page 404 /404.html;
location = /404.html
{
root <%= Rubber.root + "/public" %>;
}
}
config/environments/staging.rb
Rails.application.configure do
config.host = "dev.server.com"
config.action_mailer.default_url_options = { host: config.host }
Rails.application.routes.default_url_options = { host: config.host }
ActionMailer::Base.smtp_settings = {
user_name: 'xxxxxxx',
password: 'xxxxxxxx',
domain: config.host,
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.force_ssl = true
config.log_level = :info
config.asset_host = "http://#{ENV['FOG_DIRECTORY']}.s3-us-west-2.amazonaws.com"
config.action_controller.asset_host = config.asset_host
config.action_mailer.asset_host = config.asset_host
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
CDN 通常会允许任一协议。如果您使用的是 http 协议,则 https 将起作用,以防在开发或临时服务器中出现。
反之则不行。
切换为使用 'https'
config.asset_host = "http://#{ENV['FOG_DIRECTORY']}.s3-us-west-2.amazonaws.com"
我刚刚使用 Rubber & Capist运行o 在我的 Rails 应用程序上完成了 SSL 证书的安装。现在,我的应用程序没有显示任何样式,图像很大,javascript 也不再工作了。
此应用程序之前部署在 AWS 中,只能使用 HTTP,因此我对 Rubber 部署配置文件进行了更改,运行 cap deploy
,现在这是结果。
它应该是这样的:
这是开启 SSL 后的样子:
以下是我修改的文件:
rubber/role/nginx/unicorn_nginx.conf
<%
@path = "/etc/nginx/rubber/unicorn_nginx.conf"
%>
upstream unicorn_server {
# This is the socket we configured in unicorn.rb
server unix:/var/run/unicorn.sock
fail_timeout=0;
}
server {
listen 80;
<% if Rubber.env == 'production' %>
# SSL
listen 443 ssl;
ssl_certificate /etc/ssl/mycert.crt;
ssl_certificate_key /etc/ssl/private/server.key;
<% end %>
<% if Rubber.env == 'staging' %>
# SSL Cap
listen 443 ssl;
ssl_certificate /etc/ssl/mycert.crt;
ssl_certificate_key /etc/ssl/server.key;
<% end %>
client_max_body_size 4G;
server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;
keepalive_timeout 5;
# Location of our static files
root <%= Rubber.root + "/public" %>;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
<% if Rubber.env == 'production' || Rubber.env == 'staging' %>
proxy_set_header X-Forwarded-Proto https;
<% end %>
proxy_redirect off;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://unicorn_server;
break;
}
}
# 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/system/maintenance.html)
{
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
error_page 500 502 503 504 /500.html;
location = /500.html
{
root <%= Rubber.root + "/public" %>;
}
error_page 404 /404.html;
location = /404.html
{
root <%= Rubber.root + "/public" %>;
}
}
config/environments/staging.rb
Rails.application.configure do
config.host = "dev.server.com"
config.action_mailer.default_url_options = { host: config.host }
Rails.application.routes.default_url_options = { host: config.host }
ActionMailer::Base.smtp_settings = {
user_name: 'xxxxxxx',
password: 'xxxxxxxx',
domain: config.host,
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.force_ssl = true
config.log_level = :info
config.asset_host = "http://#{ENV['FOG_DIRECTORY']}.s3-us-west-2.amazonaws.com"
config.action_controller.asset_host = config.asset_host
config.action_mailer.asset_host = config.asset_host
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
CDN 通常会允许任一协议。如果您使用的是 http 协议,则 https 将起作用,以防在开发或临时服务器中出现。
反之则不行。
切换为使用 'https'
config.asset_host = "http://#{ENV['FOG_DIRECTORY']}.s3-us-west-2.amazonaws.com"