在我使用capistrano部署并配置了nginx.conf后,nginx返回404

时间:2014-02-15 08:23:09

标签: ruby-on-rails nginx capistrano passenger linode

我已经使用capistrano在Ryan Bates 335教程之后部署了我的rails应用程序。

当我转到我的网址时,我收到404错误,我不知道为什么。即使我运行sudo service nginx stop,它也不会停止服务器。

现在我有以下设置

Linode服务器:

  • Ubuntu 12.04 LTS
  • rbenv
  • ruby​​ 1.9.3-p194
  • 的PostgreSQL
  • nginx的乘客

我的nginx.conf位于/opt/nginx/conf/nginx.conf

user www-data;
worker_processes 4;

pid /var/run/nginx.pid;

worker_rlimit_nofile 8192;

events {
    worker_connections 8000;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay off;
    types_hash_max_size 2048;
  server_tokens off;

    include /opt/nginx/conf/mime.types;
    default_type application/octet-stream;

    # Seconds
    keepalive_timeout 20;

    ##
    # Logging Settings
    ##

  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
      '"$request" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /home/aurelien/apps/my-app/shared/log/access.log; # I created a log file there
    error_log /home/aurelien/apps/my-app/shared/log/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
  gzip_http_version 1.0;
  gzip_comp_level 5;
  gzip_min_length 512;
  gzip_buffers 4 8k;
  gzip_proxied any;
  # text/html is always compressed by HttpGzipModule
  gzip_types text/css text/plain text/x-component application/javascript application/json application/xml application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon;
  # No gzip support for > IE6
  gzip_disable        "MSIE [1-6]\.";
  gzip_vary           on;

    ##
    # nginx-passenger config
    ##

    passenger_root /home/aurelien/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/passenger-4.0.37;
    passenger_ruby /home/aurelien/.rbenv/versions/1.9.3-p194/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /opt/nginx/sites-enabled/*;
}

在我的rails app / home / aurelien / apps / my-app / current / config我有另外一个nginx.conf文件,包含以下内容

server {
    listen 80;
    server_name XXX.XXX.XX.XX;
    root /home/aurelien/apps/my-app/current/public;
    passenger_enabled on;


    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
    }

    error_page 500 422 404 /500.html;
}

我真的不知道我做错了什么,我不知道如何调试。我真的希望尽快在线获取我的rails应用程序。

当我运行命令cap deploy:update时,它并不总是更新current目录中的文件。我不知道为什么,即使github上的文件是最新的。这是我的deploy.rb以供参考:

require "bundler/capistrano"

server "XXX.XXX.XX.XX", :web, :app, :db, primary: true

set :application, "my-app"

set :user, "aurelien"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :keep_releases, 3
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
default_run_options[:pty] = true
set :scm, :git
set :repository, "git@github.com:aurelien/#{application}.git"
# using local git
# set :repository, "file:///var/git/#{application}.git"
# set :local_repository, "aurelien@example.com:/var/git/#{application}.git"
set :ssh_options, { :forward_agent => true }
# ssh_options[:forward_agent] = true
set :branch, "master"

# after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup" # keep only the last 5 releases
before 'deploy:finalize_update', 'deploy:assets:symlink'
after 'deploy:update_code', 'deploy:assets:precompile'

# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

namespace :deploy do

  desc "restart passenger server"
  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

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /opt/nginx/conf/nginx.conf"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
    run "mkdir -p #{shared_path}/uploads"
    puts "==> IMPORTANT!!! Now edit database.yml in #{shared_path}/config <==="
  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"
    # run "rm -rf #{release_path}/public/uploads"
    # run "ln -nfs #{shared_path}/uploads #{release_path}/public/"
  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
    else
      puts "Git is in sync!"
      exit
    end
  end
  before "deploy", "deploy:check_revision"

  namespace :assets do

    task :precompile, :roles => :web, :except => {:no_release => true} do
      from = source.next_revision(current_revision) rescue nil
      if from.nil? || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
        run_locally("rake assets:clean && rake assets:precompile")
        run_locally "cd public && tar -jcf assets.tar.bz2 assets"
        top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
        run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
        run_locally "rm public/assets.tar.bz2"
        run_locally("rake assets:clean")
      else
        logger.info "Skipping asset precompilation because there were no asset changes"
      end
    end

    task :symlink, roles: :web do
      run ("rm -rf #{latest_release}/public/assets &&
      mkdir -p #{latest_release}/public &&
      mkdir -p #{shared_path}/assets &&
      ln -s #{shared_path}/assets #{latest_release}/public/assets")
    end
  end


end

0 个答案:

没有答案