4

This is my first time deploying a rails app and I'm finding the process very frustrating. For work related reasons we are using Rackspace cloud with Ubuntu 12.04 LTS (Precise Pangolin) and MYSQL instead of the Heroku route.

I've been trying to figure this out for 2+ days and I'm finally turning to the community for help. Currently I'm getting a "404 Not Found Error on my server"

I've followed Ryan's Screencasts on "Deploying to a VPS", "Capistrano Recipes", this tutorial, and others on google etc. and I'm still not quite there.

I managed to get the following installed:

  • Node.js
  • RVM
  • ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
  • Rails 3.2.8
  • MYSQL
  • Passenger
  • Nginx

I'm pretty sure I'm missing something simple in my Capistrano Deployer here:

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

Is there something I should be doing before deploying?

Here are Nginx error logs:

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 Server Config File:

    #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;
    #    }
    #}

}

Thanks.

DaveG
  • 1,203
  • 1
  • 25
  • 45
  • Have you tried placing your application's nginx configurations in a new server block? I remembered I encountered something similar. – gerky Sep 16 '12 at 04:23
  • Thanks for the suggestion, I just tried that based on your comment, it did not work. – DaveG Sep 16 '12 at 04:45
  • I'm not sure what the purpose of the "client" ip address is in the log files. That isn't correct at all. I don't know where that is coming from – DaveG Sep 16 '12 at 04:47
  • I think that's where you're accessing the site from. Is your cap deploy command running successfully? – gerky Sep 16 '12 at 04:52
  • No, actually I'm getting an error in the end of it. See post above – DaveG Sep 16 '12 at 04:59
  • 1
    Something's wrong with your Bundler, check out http://stackoverflow.com/questions/3737678/rails-3-bundler-capistrano-errors – gerky Sep 16 '12 at 05:07
  • Wow...that helped a ton. I've updated my code that officially got Capistrano working. I'm still getting the "404" not found error. I've updated my logs above – DaveG Sep 16 '12 at 05:59
  • Cool, have you tried moving the nginx configuration to a new server block after deploying successfully? – gerky Sep 16 '12 at 06:06
  • I've tried adding a new block and/or leaving the existing block, and/or replacing existing block's contents and it's still now working. I'm adding my updated error logs and nginx.config file above. – DaveG Sep 16 '12 at 23:25

2 Answers2

2

Ok so I ended up figuring out the problem with trial and error and from Beef Jerky's comments.

The first issues was capistrano was unable to install some gem's from my application that had dependencies. So I installed those on production...specifically rvm capistrano gem and rmagick. The RVM Capistrano gem was the main problem and reason I was getting errors when I depoloyed. The rmagick came after fixing the rvm problem which I resolved by installing it's dependents.

The second issue I was having was pointing to my apps folder myapp/public instead of the current release myapp/current/public in the Nginx server config file. So I kept the existing server block and placed my settings inside and then it worked. Below are the settings for the Nginx server config file

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;
    #    }
    #}

}
Community
  • 1
  • 1
DaveG
  • 1,203
  • 1
  • 25
  • 45
1

I had a similar error some time ago in my first deploy.

In my case I had set a wrong path in the file mod-http-passenger.conf

My recommendation is to enable passenger_friendly_error_pages in the nginx settings for more error information. In some cases it seems to be better than the logs.

On server side

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

Add

passenger_friendly_error_pages on;
F C Torres
  • 41
  • 5