4

Railsアプリをデプロイするのはこれが初めてで、プロセスが非常にイライラしています。仕事上の理由から、Heroku ルートの代わりに Ubuntu 12.04 LTS (Precise Pangolin) と MYSQL で Rackspace クラウドを使用しています。

私はこれを2日以上理解しようとしてきましたが、最終的にコミュニティに助けを求めています. 現在、「サーバーで 404 Not Found エラー」が発生しています。

「Deploying to a VPS」、「Capistrano Recipes」、このチュートリアル、およびその他の Google などの Ryan のスクリーンキャストをフォローしましたが、まだ十分ではありません。

私は以下をインストールすることができました:

  • Node.js
  • RVM
  • ruby 1.9.3p194 (2012-04-20 リビジョン 35410) [x86_64-linux]
  • レール 3.2.8
  • MYSQL
  • 乗客
  • ニンクス

ここで私のCapistrano Deployerに単純なものが欠けていると確信しています:

require "bundler/capistrano"

server "198.101.242.242", :web, :app, :db, primary: true

set :application, "myapp"
set :user, "deployer"
set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:xxxx/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

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

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

# If you are using Passenger mod_rails uncomment this:
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

デプロイする前にやるべきことはありますか?

Nginx エラー ログは次のとおりです。

2012/09/16 23:22:17 [error] 13939#0: *1 "/home/deployer/myapp/public/index.html" is not found (2: No such file or directory), client: ip, server: localhost, request: "GET / HTTP/1.1", host: "ip"
2012/09/16 23:22:17 [error] 13939#0: *1 open() "/home/deployer/myapp/public/favicon.ico" failed (2: No such file or directory), client: ip, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "65.61.189.109"
2012/09/16 23:22:19 [error] 13939#0: *1 "/home/deployer/myapp/public/index.html" is not found (2: No such file or directory), client: ip, server: localhost, request: "GET / HTTP/1.1", host: "ip"
2012/09/16 23:22:19 [error] 13939#0: *1 open() "/home/deployer/myapp/public/favicon.ico" failed (2: No such file or directory), client: ip, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "ip"

Nginx サーバー構成ファイル:

    #user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /home/deployer/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17;
    passenger_ruby /home/deployer/.rvm/wrappers/ruby-1.9.3-p194/ruby;

    include       mime.types;
    default_type  application/octet-stream;

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

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {

      listen 80;
      server_name localhost;
      location / {
            root /home/deployer/myapp/public;   # <--- be sure to point to 'public'!
      }
      passenger_enabled on;

        # listen       80;
        # server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # location / {
        #     root   html;
        #     index  index.html index.htm;
        # }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;
        # location = /50x.html {
        #     root   html;
        # }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

   # server {
   #    listen 80;
   #    server_name localhost;
   #      location / {
   #            root /home/deployer/myapp/public;   # <--- be sure to point to 'public'!
   #    }
   #      passenger_enabled on;
   # }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

ありがとう。

4

2 に答える 2

2

わかりましたので、試行錯誤とビーフジャーキーのコメントから問題を突き止めました。

最初の問題は、capistrano が依存関係のあるアプリケーションからいくつかの gem をインストールできなかったことです。だから私はそれらを本番環境にインストールしました...具体的にはrvm capistrano gemとrmagickです。RVM Capistrano gem が主な問題であり、デプロイ時にエラーが発生する理由でした。rmagickは、依存関係をインストールすることで解決したrvmの問題を修正した後に発生しました。

私が抱えていた 2 番目の問題は、Nginx サーバー構成ファイルの現在のリリース myapp/current/public ではなく、アプリ フォルダー myapp/public を指していたことです。したがって、既存のサーバーブロックを保持し、設定を内部に配置すると、機能しました。以下は、Nginxサーバー構成ファイルの設定です

server {

      listen 80;
      server_name localhost;
      root /home/deployer/banking_analytics/current/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;

        # listen       80;
        # server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # location / {
        #     root   html;
        #     index  index.html index.htm;
        # }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;
        # location = /50x.html {
        #     root   html;
        # }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

   # server {
   #    listen 80;
   #    server_name localhost;
   #      location / {
   #            root /home/deployer/banking_analytics/public;   # <--- be sure to point to 'public'!
   #    }
   #      passenger_enabled on;
   # }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
于 2012-09-16T23:51:57.260 に答える
1

少し前に、最初のデプロイで同様のエラーが発生しました。

私の場合、ファイル mod-http-passenger.conf に間違ったパスを設定していました

私のお勧めは、nginx 設定で Passenger_friendly_error_pages を有効にして、より多くのエラー情報を取得することです。場合によっては、ログよりも優れているようです。

サーバー側

sudo vim /etc/nginx/sites-enabled/myApp

追加

passenger_friendly_error_pages on;
于 2020-05-20T20:06:18.820 に答える