404 Nginx error - Ubuntu 14.04 Rails

November 16, 2014 5.3k views

Hey guys,

I am following this tutorial with my own rails project: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

And I keep arriving at a 404 Nginx not found error. Printing out the log I recieved this error: 2014/11/16 14:08:13 [error] 20149#0: *29 "/home/rails/whattodo/public/index.html" is not found (2: No such file or directory), client: 70.52.174.228, server: , request: "GET / HTTP/1.1", host: "104.131.76.121"
2014/11/16 14:08:14 [error] 20149#0: *29 open() "/home/rails/whattodo/public/favicon.ico" failed (2: No such file or directory), client: 70.52.174.228, server: , request: "GET /favicon.ico HTTP/1.1", host: "104.131.76.121".

Here is my nginx file:
server {
listen 80 defaultserver;
passenger
enabled on;
passengerappenv development;
root /home/rails/whattodo/public;
}

I added this file, even though I didn't think it would be necessary, and still the error remains. Any help or directions you think I should be heading to solve this problem would be greatly appreciated!

2 comments
  • Here is my nginx file:
    server {
    listen 80 defaultserver;
    passengerenabled on;
    passengerappenv development;
    root /home/rails/whattodo/public;
    }

    change rails -> current_user

    root /home/CURRENTUSER/whattodo/public;
    and add server
    name DROPLET_IP

    server {
    listen 80 defaultserver;
    and add servername DROPLETIP;
    passengerenabled on;
    passengerappenv development;
    root /home/CURRENT_USER/whattodo/public;
    }

  • I'm having the same error as this....

    it seems as if Passenger is is not serving up the resource route for leads, although I have it specified in routes.rb. this is my log below - (i've blanked out my local IP address)

    I, [2015-04-03T14:46:36.079982 #31343] INFO -- : Rendered layouts/header.html.erb (0.1ms)
    I, [2015-04-03T14:46:36.080752 #31343] INFO -- : Rendered layouts/
    footer.html.erb (0.1ms)
    I, [2015-04-03T14:46:36.081338 #31343] INFO -- : Completed 200 OK in 107ms (Views: 101.9ms | ActiveRecord: 0.0ms)
    I, [2015-04-03T14:46:49.744553 #31343] INFO -- : Started GET "/" for ... at 2015-04-03 14:46:49 -0400
    I, [2015-04-03T14:46:49.747872 #31343] INFO -- : Processing by PagesController#index as HTML
    I, [2015-04-03T14:46:49.886582 #31343] INFO -- : Rendered layouts/leadsform.html.erb (134.5ms)
    I, [2015-04-03T14:46:49.886954 #31343] INFO -- : Rendered pages/index.html.erb within layouts/application (136.7ms)
    I, [2015-04-03T14:46:49.888229 #31343] INFO -- : Rendered layouts/
    header.html.erb (0.1ms)
    I, [2015-04-03T14:46:49.888699 #31343] INFO -- : Rendered layouts/footer.html.erb (0.1ms)
    I, [2015-04-03T14:46:49.889101 #31343] INFO -- : Completed 200 OK in 141ms (Views: 139.6ms | ActiveRecord: 0.0ms)
    I, [2015-04-03T15:42:04.922230 #1363] INFO -- : Started GET "/" for ... at 2015-04-03 15:42:04 -0400 #### Me hitting the page
    I, [2015-04-03T15:42:05.051669 #1363] INFO -- : Processing by PagesController#index as HTML
    I, [2015-04-03T15:42:05.253623 #1363] INFO -- : Rendered layouts/
    leadsform.html.erb (124.1ms)
    I, [2015-04-03T15:42:05.261614 #1363] INFO -- : Rendered pages/index.html.erb within layouts/application (140.6ms)
    I, [2015-04-03T15:42:05.268565 #1363] INFO -- : Rendered layouts/header.html.erb (0.8ms)
    I, [2015-04-03T15:42:05.272103 #1363] INFO -- : Rendered layouts/
    footer.html.erb (1.0ms)
    I, [2015-04-03T15:42:05.274183 #1363] INFO -- : Completed 200 OK in 220ms (Views: 163.7ms | ActiveRecord: 28.7ms)#### the view being rendered

    Nothing happens after that and i get a 404 error when i click on my submit form button (which points to a controller 'leads')

    why is this happening?

1 Answer

The best solution I could find to this after searching a lot was to re-install and configure nginx with phusion passenger

sudo apt-get purge nginx nginx-common nginx-full
sudo apt-get install nginx
sudo nano /etc/nginx/nginx.conf
# uncomment 'passenger_root' & 'passenger_ruby' paths accordingly
sudo nano /etc/nginx/sites-enabled/default
# replace with:
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    server_name mydomain.com;
    passenger_enabled on;
    rails_env    production;
    root         /home/deploy/myapp/current/public;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
sudo service nginx restart
Have another answer? Share your knowledge.