我正在尝试部署我的第一个适当的 Rails 项目。我有一个安装了 Nginx、Passenger 和 PostgreSQL 的 Ubuntu 12.04 虚拟服务器。我已使用 Capistrano 将代码部署到服务器。
一切都应该正常工作,但由于某种原因,当尝试通过浏览器访问页面时,它只是尝试连接大约 10 秒然后超时。但是,所有静态页面,例如 address/500.html 和 address/robots.txt 都可以正确加载。
我在 /opt/nginx/logs 检查了 Nginx 错误日志,但它们是空的。另一方面,Nginx 访问日志只记录了我的一些尝试。Nginx 访问日志:
130.233.194.3 - - [18/Sep/2012:11:13:04 +0300] "GET /somestuff HTTP/1.1" 301 5 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
130.233.194.3 - - [18/Sep/2012:11:37:59 +0300] "GET /500.html HTTP/1.1" 200 643
"-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
130.233.194.3 - - [18/Sep/2012:11:45:59 +0300] "-" 400 0 "-" "-"
130.233.194.3 - - [18/Sep/2012:11:57:32 +0300] "GET /500.html HTTP/1.1" 200 643
"-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
130.233.194.3 - - [18/Sep/2012:11:57:47 +0300] "GET /favicon.ico HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
130.233.194.3 - - [18/Sep/2012:11:58:19 +0300] "GET /robots.txt HTTP/1.1" 200 204 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
(例如,在 /somestuff 之后,我尝试了 /nopage,但它没有被记录)
我的 Rails 应用程序生产日志仅显示数据库迁移。我也可以在生产模式下打开 Rails 控制台并将内容写入数据库,所以我认为这不是问题。
如果我在rails控制台中写“app.get(”/“)”或任何其他页面,它只会返回301(不知道这是否相关,在我的开发环境中它返回200)
以下是一些可能相关的其他文件:
nginx.conf:
#user [User used in deploying];
server {
listen 80;
server_name [Name_of_the_server];
root /home/[User used in deploying]/srv/nsbg/current/public;
passenger_enabled on;
}
(这是我添加的,否则默认)
Capistrano 部署文件:
require 'bundler/capistrano'
set :user, '[User used in deploying]'
set :domain, '[server name]'
set :applicationdir, "/home/[User used in deploying]/srv/nsbg"
set :scm, 'git'
set :repository, "[Github repo]"
set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# additional settings
default_run_options[:pty] = true # Forgo errors when deploying from windows
#ssh_options[:keys] = %w(/home/user/.ssh/id_rsa) # If you are using ssh_keysset :chmod755, "app config db lib public vendor script script/* public/disp*"set :use_sudo, false
# Passenger
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
使用命令“sudo 乘客状态”:
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
Waiting on global queue: 0
----------- Application groups -----------
/home/[User used in deploying]/srv/nsbg/current:
App root: /home/[User used in deploying]/srv/nsbg/current
* PID: 8038 Sessions: 0 Processed: 1 Uptime: 1h 4m 29s
就像我说的那样,静态页面得到服务,但任何其他页面(包括无效路由)都会挂断,并且不会在任何地方写入错误。请帮助我,我在部署方面非常缺乏经验并且完全迷失了