Why my Rails app works without sites-available directory and even with default Nginx config?

May 11, 2016 343 views
Nginx Ruby on Rails

I'm playing around with my first droplet (it was Ubuntu 14.04 clean install). I already have a Rails application on it running and I want to setup a Wordpress blog aside as well. So I'm trying to understand how everything works together, how it's settings affects on my applications work. I have nginx and passenger and postgresql.

I used this tutorial for initial sutup and this one for Rails.

So now i decided to remove symlink from my /etc/nginx/sites-enabled directory. And it didn't change anything. My rails app was working. With the empty directory. Then I emptied /etc/nginx/sites-available directory as well. And again it had no effect on my rails app. And this is my first question: why?

This is how I start my Rails server by the way:

RAILS_ENV=production rails server --binding=my_ip

And I'm using these Nginx commands:

sudo service nginx start
sudo service nginx stop
sudo service nginx restart

So after it I deleted nginx.conf file. And there I finally couldn't start Nginx

cat: /etc/nginx/nginx.conf: No such file or directory

And my Rails app also stopped working.

Then I restored it (nginx.conf) but commented those settings which I added there to set the Rails connection:

#passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_ruby /usr/bin/passenger_free_ruby;

But according to this tutorial these lines are needed to be uncommented.

But my Rails app is again working even without those lines. Why?

So at the moment my rails app is running in production with my /etc/nginx/sites-available and /etc/nginx/sites-enabled folders empty and here is my current nginx.conf file:

user www-data;
worker_processes 4;
pid /run/;

events {
    worker_connections 768;

http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

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

    gzip on;
    gzip_disable "msie6";

    #passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    #passenger_ruby /usr/bin/passenger_free_ruby;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

And this totally make no sense to me. Why do I need these nginx.conf settings and these folders (sites-enabled and sites-available) with configs in it and symlinks if my app doesn't need it to work?

1 Answer


Something appears missing if it's still running with this setup. Have you fully stopped and restarted nginx and ruby on rails?

Have you also ensured that the /etc/nginx/conf.d/*.conf directory doesn't hold any conf files that may contain your server blocks?

To confirm as well, the app is running on port 80, not another port such as 3000 and you are connecting to that?

If you are connecting on a port other than 80, then it's not nginx running your application, it's something else.

Have another answer? Share your knowledge.