3

I have set up nginx (nginx.conf below) and thin. Both nginx and thin (2 servers) are running (I have checked they are running). I can access a static page in the rails public directory such as index.html but if I put in any other url I get a 500 page generated by nginx saying 'We're sorry, but something went wrong.' Any help on what I am doing wrong is appreciated. I want to be able to access the rails application.

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

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

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

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout 30;

#gzip  on;

# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;

#Rails app config here
upstream Backend  {
      server 127.0.0.1:3000;
      server 127.0.0.1:3001;
}

server {
       listen   80;
       server_name www.domain.com;
       rewrite ^/(.*) http://domain.com permanent;
}


server {
        listen   80;
                    server_name domain.com;

        access_log /applications/RailsApp/log/access.log;
        error_log /applications/RailsApp/log/error.log;

        root /applications/RailsApp/public;
        # index  index.html;

        location / {
                      proxy_set_header  X-Real-IP  $remote_addr;
                      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                      proxy_set_header Host $http_host;
                      proxy_redirect off;

                      if (-f $request_filename/index.html) {
                                       rewrite (.*) $1/index.html break;
                      }

                      if (-f $request_filename.html) {
                                       rewrite (.*) $1.html break;
                      }

                      if (!-f $request_filename) {
                                       proxy_pass http://Backend;
                                       break;
                      }
        }

 }

}

This exactly my nginx.conf except for domain.com here is a placeholder for the actual domain.

ajeetdl
  • 141
  • 5
  • 1
    What does nginx's error.log contain? I've never seen such a message from nginx though, so I'd suspect that the 500 response is from Rails, not nginx. – mgorven May 21 '12 at 00:26
  • You may be correct, the nginx error log does not contain any recent errors. – ajeetdl May 21 '12 at 01:24

1 Answers1

1

After realizing that the error was from rails and not nginx or thin the issue was resolved fairly quickly by checking log/production.log in my Rails application. I had two problems.

First the socket for my production db in config/database.yml was incorrect. I had to change it from the incorrect socket: tmp/mysql.sock to where it actually is on my system, socket: var/lib/mysql/mysql.sock.

After this there was another error in log/production.log about a css file not being precompiled. This was fixed by editing config/environments/production.rb and changing 'config.assets.compile = false' to 'config.assets.compile = true'.

ajeetdl
  • 141
  • 5