- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
用这个把我的头发拉出来后,恐怕我将不得不把那些人的知识变得更聪明......再次!
好的,问题来了,我正在关注以下两个 railscast:
deploying to a vps
asset pipeline in production
我的设置:
Ubuntu 服务器 12.04
nginx
unicorn
ruby 1.9.3p125
rails 3.2.2
据我所知,所有内容都跟在 T 之后(或 Tea 或 Tee,我以前从未见过写下这个短语)。该站点现在正在我的服务器上运行,但未加载样式表和 javascript 文件。这似乎与 Rails 3.1 404 Error when loading .css files that are present in public/assets 是同一个问题或 Rails 404 error for Stylesheet or JavaScript files .虽然第一个没有答案,但后者表明这可能是网络服务器没有寻找静态资源的问题,也许不应该。
有人知道是什么原因造成的吗?
一些事实:
首先,我遇到了一些关于预编译的令人讨厌的错误,并注意到我的个人 css/js 文件已被缩小到它们的应用程序副本中,因此我更改了它们在 ruby 帮助程序中的声明以反射(reflect)这一点。
当我更改为 config.serve_static_assets = true
时,应用程序在本地运行在 config/environments/production.rb
这是我服务器上的生产.log 转储
Started GET "/main" for 92.237.28.149 at 2012-07-09 23:08:02 +0100
Processing by MainController#index as HTML
Rendered shared/_login_form.html.erb (0.4ms)
Rendered shared/_footer.html.erb (0.4ms)
Rendered shared/_details_form.html.erb (7.7ms)
Rendered main/index.html.erb within layouts/main_logged (17.1ms)
Completed 200 OK in 21ms (Views: 20.5ms | ActiveRecord: 0.0ms)
Compiled jquery.js (2ms) (pid 8253)
Compiled jquery_ujs.js (0ms) (pid 8253)
Compiled admin_user.js (227ms) (pid 8253)
Compiled construction.js (227ms) (pid 8253)
Compiled google-map.js (0ms) (pid 8253)
Compiled jquery-1.2.6.min.js (1ms) (pid 8253)
Compiled jquery-ui-personalized-1.5.2.packed.js (0ms) (pid 8253)
Compiled login.js (227ms) (pid 8253)
Compiled main.js (222ms) (pid 8253)
Compiled menu.js (223ms) (pid 8253)
Compiled order_steps.js (225ms) (pid 8253)
Compiled register_user.js (223ms) (pid 8253)
Compiled sprinkle.js (0ms) (pid 8253)
Compiled sticky_basket/jquery.easing.1.3.js (0ms) (pid 8253)
Compiled sticky_basket/stickysidebar.jquery.js (0ms) (pid 8253)
Compiled sticky_basket/stickysidebar.jquery.min.js (0ms) (pid 8253)
Compiled user.js (292ms) (pid 8253)
Compiled application.js (2155ms) (pid 8253)
Compiled admin_user.css (12ms) (pid 8253)
Compiled construction.css (0ms) (pid 8253)
Compiled construction.css (1ms) (pid 8253)
Compiled lightbox.css (0ms) (pid 8253)
Compiled login.css (1ms) (pid 8253)
Compiled main.css (0ms) (pid 8253)
Compiled login.css (1ms) (pid 8253)
Compiled main.css (0ms) (pid 8253)
Compiled main.css (2ms) (pid 8253)
Compiled menu.css (1ms) (pid 8253)
Compiled menu_style.css (0ms) (pid 8253)
Compiled normalise.css (0ms) (pid 8253)
Compiled order_steps.css (0ms) (pid 8253)
Compiled order_steps.css (1ms) (pid 8253)
Compiled register_user copy.css (0ms) (pid 8253)
Compiled register_user.css (0ms) (pid 8253)
Compiled register_user.css (1ms) (pid 8253)
Compiled tab_style.css (0ms) (pid 8253)
Compiled user.css (1ms) (pid 8253)
Compiled application.css (236ms) (pid 8253)
Compiled jquery.js (2ms) (pid 8253)
Compiled jquery_ujs.js (0ms) (pid 8253)
Compiled admin_user.js (273ms) (pid 8253)
Compiled construction.js (225ms) (pid 8253)
Compiled google-map.js (0ms) (pid 8253)
Compiled jquery-1.2.6.min.js (1ms) (pid 8253)
Compiled jquery-ui-personalized-1.5.2.packed.js (0ms) (pid 8253)
Compiled login.js (269ms) (pid 8253)
Compiled main.js (225ms) (pid 8253)
Compiled menu.js (224ms) (pid 8253)
Compiled order_steps.js (226ms) (pid 8253)
Compiled register_user.js (224ms) (pid 8253)
Compiled sprinkle.js (0ms) (pid 8253)
Compiled sticky_basket/jquery.easing.1.3.js (0ms) (pid 8253)
Compiled sticky_basket/stickysidebar.jquery.js (0ms) (pid 8253)
Compiled sticky_basket/stickysidebar.jquery.min.js (0ms) (pid 8253)
Compiled user.js (224ms) (pid 8253)
Compiled application.js (2096ms) (pid 8253)
Compiled admin_user.css (12ms) (pid 8253)
Compiled construction.css (0ms) (pid 8253)
Compiled construction.css (1ms) (pid 8253)
Compiled lightbox.css (0ms) (pid 8253)
Compiled login.css (1ms) (pid 8253)
Compiled main.css (0ms) (pid 8253)
Compiled login.css (1ms) (pid 8253)
Compiled main.css (0ms) (pid 8253)
Compiled main.css (1ms) (pid 8253)
Compiled menu.css (2ms) (pid 8253)
Compiled menu_style.css (0ms) (pid 8253)
Compiled normalise.css (0ms) (pid 8253)
Compiled order_steps.css (0ms) (pid 8253)
Compiled order_steps.css (1ms) (pid 8253)
Compiled register_user copy.css (0ms) (pid 8253)
Compiled register_user.css (0ms) (pid 8253)
Compiled register_user.css (1ms) (pid 8253)
Compiled tab_style.css (0ms) (pid 8253)
Compiled user.css (1ms) (pid 8253)
Compiled application.css (179ms) (pid 8253)
Started GET "/main" for 92.237.28.149 at 2012-07-09 23:15:00 +0100
Processing by MainController#index as HTML
Rendered shared/_login_form.html.erb (1.2ms)
Rendered shared/_footer.html.erb (1.1ms)
Rendered shared/_details_form.html.erb (15.5ms)
Rendered main/index.html.erb within layouts/main_logged (80.9ms)
Completed 200 OK in 142ms (Views: 140.4ms | ActiveRecord: 0.0ms)
Started GET "/main" for 92.237.28.149 at 2012-07-09 23:33:54 +0100
Processing by MainController#index as HTML
Rendered shared/_login_form.html.erb (1.2ms)
Rendered shared/_footer.html.erb (1.1ms)
Rendered shared/_details_form.html.erb (15.6ms)
Rendered main/index.html.erb within layouts/main_logged (80.7ms)
Completed 200 OK in 142ms (Views: 140.0ms | ActiveRecord: 0.0ms)
如你所见,没有更多关于预编译的提示
这里是生成的html
<title>HTML Snippet</title>
<link href="/assets/application-dd445a707b7e96c914afd14bf1f02bbc.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/application-def3878140cda305cb0ca5ef745fd758.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
<script src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js" type="text/javascript"></script>
如果我点击这些链接,它们会生成一个 nginx 404,但如果我将 url 更改为 http://<ipaddress>/public/assets/application-dd445a707b7e96c914afd14bf1f02bbc.css
我得到一个 rails 生成 The page you were looking for doesn't exist.
这是我服务器上/public/assets 的重要(我认为)内容
application-7c90c01effcf9d8593e28e4c4b716ac2.css
application-7c90c01effcf9d8593e28e4c4b716ac2.css.gz
application.css
application.css.gz
application-dd445a707b7e96c914afd14bf1f02bbc.css
application-dd445a707b7e96c914afd14bf1f02bbc.css.gz
application-def3878140cda305cb0ca5ef745fd758.js
application-def3878140cda305cb0ca5ef745fd758.js.gz
application.js
application.js.gz
最后,我不太清楚的领域,只是涵盖了所有内容,这里是 railscast 中用于配置 capistrano、nginx 和 unicorn 的文件:
我取消了 load 'deploy/assets'
的注释在顶文件中
部署.rb
require "bundler/capistrano"
server "92.237.28.149", :web, :app, :db, primary: true
set :application, "little_oven_deploy"
set :user, "daz"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@bitbucket.org:DanBaldwin/little_oven_deploy.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
nginx.conf
upstream unicorn {
server unix:/tmp/unicorn.little_oven_deploy.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/blog/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
unicorn .rb
root = "/home/daz/apps/little_oven_deploy/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.little_oven_deploy.sock"
worker_processes 2
timeout 30
unicorn_init.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/daz/apps/little_oven_deploy/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=daz
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit 1
;;
esac
unicorn_init.sh 也是 chmod +x。
对于信息可能过载的家伙,我们深表歉意,但如果它能帮助您大致了解我的问题,那么它有助于获得诊断,非常感谢任何帮助。
提前致谢
最佳答案
如果 nginx 不提供静态资源,那可能是因为 root
指令中的拼写错误。三次检查它是否正确引用了您的 Rails 公用文件夹。
就我而言,我忘记了我将我的应用程序移到了另一个位置。这并没有完全破坏应用程序,因为 nginx 仍然能够 proxy_pass
请求通过我的 unicorn 套接字,它没有移动。
如果您收到来自 Rails 应用程序的响应,请不要假设您的应用程序已正确连接。 root 指令必须指向正确的文件夹才能解析静态 Assets 。
server {
...
# make absolutely sure this is pointing to your app/public folder
root /home/deployer/apps/blog/current/public;
...
}
关于ruby-on-rails - Rails 3.2.2 在使用 capistrano 部署后在样式表和 js Assets 上获得 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11404502/
我是 Capistrano 的新手,我想知道为我的项目管理 Capistrano 配置的最佳方法是什么。 具体应该在哪里config/deploy.rb与我的项目的源代码控制相关吗?我应该存储没有特定
我正在使用 Capistrano 管理在多个负载平衡服务器上运行的 Java Web 应用程序。某些任务(例如配置更改)需要重新启动服务器或重新部署应用程序,在此期间服务器变得无响应。 如果 Capi
有没有办法可以看到 capistrano 任务依赖树?我有一个大项目,有很多任务和依赖项,但我对整个画面一无所知。 帕纳约蒂斯 最佳答案 在 Capistrano 3 中,您可以添加 --trace
我有一个命名空间和一些在 deploy:updated 之后运行的命名空间中的任务。下面是一个例子: namespace :myservice do task :start do on r
我想在运行 deploy:migrate 任务之前停止一些进程。我知道我可以通过复制现有代码并在任务的开头和结尾添加停止/启动步骤来重新定义 deploy:migrate 任务。 我想知道是否有办法避
我将如何更改 Capistrano 使用的临时目录? 示例:代替 /tmp ,我想用/home/user/tmp 我现在的 VPS 有 /tmp安装为 noexec ,这使我在尝试运行时获得了权限被拒
使用 Capistrano,如何回滚到特定版本? 我服务器的文件夹有一个/release 文件夹,我如何回滚到特定的文件夹? 我是否可以在本地获取计算机上的版本列表? 我正在使用 GIT,但这不起作用
我尝试使用“cap rollback”,但出现以下错误: $ cap rollback the task `rollback' does not exist 我需要做一些额外的设置才能使回滚正常工作吗
我正在使用 Capistrano 部署 ruby on Rails 项目。我正在尝试以用户“部署”身份登录远程服务器并部署此应用程序。 当我通过 ssh 进入框进行部署并 git 克隆项目时,它可
我正在使用 Capistrano 部署 ruby on Rails 项目。我正在尝试以用户“部署”身份登录远程服务器并部署此应用程序。 当我通过 ssh 进入框进行部署并 git 克隆项目时,它可
我正在使用 capistrano、capistrano/rbenv、capistrano/bundler 和 capistrano/rails。我在 capistrano 编译 Assets 的步骤中
尝试将此代码块授予 capistrano 的版本 3 但无济于事。一切都变了。任何人都可以帮助我在正确的轨道上进行转换吗? 旧版本 2 deploy.rb: #require 'new_relic/r
我对这两种工具都是新手,还没有完全掌握。 如果我使用 Capistrano 进行部署,为什么 Gradle 是部署目标? 另见 Gradle Overview . 最佳答案 Gradle 是从 Gro
如何使用 Capistrano v3 仅部署到一台服务器?我在那里发现的所有解决方案都部署到每台服务器,因此,我认为它们适用于 v2。 我不想部署一个阶段,我已经在使用多阶段,我只想在其中一个阶段部署
在 Capistrano Multi-staging documentation set :deploy_env, 'production'用来。是 deploy_env同 rails_env其中te
部署应用程序时,我将 Capistrano 与 capistrano_rsync_with_remote_cache gem 一起使用。 使用新软件升级部署服务器后出现问题: 卡皮斯特拉诺 2.5.1
capistrano-chef 是否有替代品?厨师独奏的 gem ?主要是为了避免两次定义服务器信息。 最佳答案 我在这个话题上发现了一些新鲜而热门的东西: Roundsman gem 文件: gem
我正在尝试通过遵循 DOCS 来学习使用 Capistrano 3,并且我编写了一个简单的任务来测试我的理解。 任务在默认 task 中创建目录在 lib/capistrano/tasks : d
我有一个 capistrano 任务,它整合了 Rails 项目的多个阶段的部署。 例如: task :consolidated_task do build #creates a new re
来自 deploy.rb 的片段 task :prod1 do set :deploy_to, "/home/project/src/prod1" end task :prod2 do set
我是一名优秀的程序员,十分优秀!