Dunes Buggy
Dunes Buggy

Reputation: 1819

nginx and passenger to run my rails application

I'm new to Rails and trying to deploy my rails app (which runs perfectly on my computer using rails server) on to a server.

My server has nginx and passenger both installed and working fine. However, when I change the nginx config file at /opt/nginx/conf/nginx.conf as follows

....
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby1.9.1;
....
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;                                                                                                                                                                                    

    #access_log  logs/host.access.log  main;                                                                                                                                                            

    location / {
        root   /home/path_to_my_app/public;
        index  index.html index.htm;
    }

    passenger_enabled on;
}

it doesn't work. I'm not able to call my rails code. It keeps saying 404 error.

I restarted the nginx using service nginx restart which returned OK, but still no luck.

Can anyone tell how to debug this. Where should I check what all applications my passenger is running? What is the part I'm missing?

EDIT: I'm following this documentation very closely

Upvotes: 0

Views: 566

Answers (3)

Alexander Ushakov
Alexander Ushakov

Reputation: 5399

It seems that there is no /home/path_to_my_app/public directory.

In Passenger version 5.0.7 directory access has been changed. Now if root directory doesn't exist it falls back to nginx to search index.html and gives 404 error if there is now such file.

[Nginx] The Nginx module now looks for index.html if the path ends in / so that it works intuitively, without needing to use try_files.

https://blog.phusion.nl/2015/04/29/passenger-5-0-7/

Upvotes: 1

nobody0day
nobody0day

Reputation: 202

"location /" means all the HTTP request will be handled by this location's handler but there isn't one so you will get "404 not found". I guess you mean that your home page is index.html so change "location /" to "location =/" will fixed your problem.


update

server { listen 80; server_name localhost; root /path/to/public; passenger_enabled on; } There is no need add location for simple app.

Upvotes: 0

idlefingers
idlefingers

Reputation: 32037

If your server log says that passenger agents are online and if you run sudo passenger-status and see your application listed, then it would appear the agent is setup correctly.

Are you trying to access the site using localhost? If you're trying to access it from outside the server, you'll need to set server_name to either your domain or an IP address (and restart nginx after any changes). If you run curl http://localhost on the server, do you see the html from your site, or just another 404?

Upvotes: 0

Related Questions