Nginx: Welcome to nginx! page keeps showing
Asked Answered
E

1

11

I've been trying for more than a day now to make Nginx and Passenger work for my Rails app, but all I ever get is: The Nginx welcome page. Why?

I have installed Nginx in the default location /opt/nginx, like so:

# Install passenger gem
$ gem install passenger

# Install dependencies for Nginx/Passenger
$ apt-get install libcurl4-openssl-dev

# Compile it
$ passenger-install-nginx-module

And the (I think) relevant parts of the file /opt/nginx/conf/nginx.conf look like this:

http {
    passenger_root /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.29;
    passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby;

    server {
        listen       80;
        server_name  www.my-domain.com;
        root /home/deploy/current/public;
        passenger_enabled on;

        location / {
            root   html;
            index  index.html index.htm;
            passenger_enabled on;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
            passenger_enabled on;
        }

        ...

And when I check the "root location" (public), I can see that the app is there (it was deployed with Capistrano):

$ ls /home/deploy/current/public
404.html  422.html  500.html  assets  css  favicon.ico  js  robots.txt  system

...or 1 level up:

$ ls /home/deploy/current
app                  Capfile  config.ru  doc      Gemfile.lock  log  public    resque.pid  script  tmp
assets_manifest.yml  config   db         Gemfile  lib           LOG  Rakefile  REVISION    test    vendor

And looking at the Rails production.log, I can see that it never went beyond compiling assets:

$ tail -f /home/deploy/current/log/production.log
Compiled page_specific/some_file_5.css  (137ms)  (pid 28316)
Compiled page_specific/some_file_4.css  (19ms)  (pid 28316)
Compiled page_specific/some_file_3.css  (3ms)  (pid 28316)
Compiled page_specific/some_file_2.css  (3ms)  (pid 28316)
Compiled page_specific/some_file_1.css  (16ms)  (pid 28316)
Compiled application.css  (3131ms)  (pid 28316)

And looking at the Nginx error.log, I can't see anything wrong (normal visits to the URL ("home page") don't seem to create any entries):

$ tail -f /opt/nginx/logs/error.log

And looking at the Nginx access.log, I can't see anything wrong (normal visits to the URL ("home page") don't seem to create any entries):

$ tail -f /opt/nginx/logs/error.log
[ 2013-12-29 01:16:55.6792 2099/7fa534fca740 agents/Watchdog/Main.cpp:697 ]: All Phusion Passenger agents started!

Also:

  • I'm sure Nginx is running (since I see the welcome page)
  • I'm sure the nginx.conf file is being taken into account by Nginx (i.e. if I uncomment #access_log logs/access.log main; without uncommenting the #log_format main, it complains)
  • I'm on: Rails 3.2.16 / ruby 2.0.0p353 / Ubuntu 13.10

What could be wrong here?

Escapism answered 29/12, 2013 at 10:13 Comment(0)
E
13

Holy ish. All that is apparently required to make it work is:

Comment out/delete the "location /" directive which is added by default during the installation:

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

(If anybody knows why, I'd be interested to know.)

Escapism answered 29/12, 2013 at 13:4 Comment(3)
I would try to explain it: your Rails app is meant to be the ending point to the HTTP request. That's why 'location /' should be replaced with 'location passenger-your_app' (for example). Default configuration makes static page ('index.html') in charge, I guess that's not what you want.Theron
It's because Passenger requires that your root directive points to the public dir of your Rails app. Inside your location / block, your root directive is clearly pointing to somewhere else.Alexanderalexandr
Just spent ALL DAY trying to figure this one out on my own! You've saved my life TomDoggDebus

© 2022 - 2024 — McMap. All rights reserved.