Problem With Home page in ruby on Rails

December 21, 2015 1.5k views
Deployment Ruby on Rails Nginx CentOS

Hi

I had developed a application in ruby on rails and deployed with the help of this link
https://www.digitalocean.com/community/tutorials/how-to-automate-ruby-on-rails-application-deployments-using-capistrano and i have set ruby application correctly ngnix/default.conf file also but when trying to access my application through ip address its showing 404 Not Found in my browser but i have tested with html test page with same path its working fine and this is what my conf files

 server {
    listen       80;
    server_name  xxx.xxx.xxx.xxx;
    root /home/deployer/app-name/current/app/views/sessions/login.html.erb;
    passenger_enabled on;

    #charset koi8-r;
    access_log  /var/log/nginx/alemany.access.log  main;
    error_log /var/log/nginx/alemany.error.log;

    #root   /usr/share/nginx/html;
    #index index.php index.html index.htm ;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm.sock; 
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
1 Answer

The root directive shouldn't point to a specific file. Instead, it should point to the application's public/ directory. Here is a minimal working example:

 server {
    listen       80;
    server_name  xxx.xxx.xxx.xxx;
    root /home/deployer/app-name/public;
    passenger_enabled on;

    access_log  /var/log/nginx/access.log  main;
    error_log /var/log/nginx/error.log;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

Note that I also removed the location ~ \.php$ section. This is not needed for a Rails application, only PHP one.

For more information, check out this tutorial that walks through setting up Rails and Nginx with Passenger start to finish:

by O.S Tezer
In this DigitalOcean article, we are going to show you -- from start to finish -- how to have a rock solid Rails application deployment (i.e. published online) using the latest available CentOS operating system renowned for its stability. This will be alongside Phusion Passenger application server, known for its simplicity and excellent features, coupled with Nginx HTTP server running in front to handle and manage connections.
Have another answer? Share your knowledge.