0

In CentOS 7.x I've installed a Rails app which I can access through [ip]:8080. It works using ip. But when I set the domain name as a server_name (instead of localhost) mydomain.com gives me a 502 Bad Gateway problem. Ip still works.

I already restarted nginx. And the application is running with unicorn_rails. My rails log shows nothing. PD: This app is from this tutorial.

/etc/nginx/conf.d/default.conf

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}

server {

    listen 80;
    server_name mydomain.com www.mydomain.com;

    # Application root, as defined previously
    root /var/www/my_app/public;

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

/var/www/my_app/config/unicorn.rb

# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/my_app"

# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/my_app/pids/unicorn.pid"

# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/my_app/log/unicorn.log"
stdout_path "/var/www/my_app/log/unicorn.log"

# Unicorn socket
#listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.myapp.sock"

# Number of processes
# worker_processes 4
worker_processes 2

# Time-out
timeout 30

This is what my /var/log/nginx/error.log shows:

2015/02/17 14:06:34 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"
2015/02/17 14:06:36 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"

A second question, the application only executes when I run unicorn_rails, how can I make it run permanently?

Ricardo Castañeda
  • 5,746
  • 6
  • 28
  • 41
  • How come you have unicorn running on both port and sock file, check your unicorn settings and make sure it's using a sock file by default, otherwise change your upstream to pass to port 8080 – Mohammad AbuShady Feb 18 '15 at 07:58
  • 1
    what do you see after run ``sudo service nginx restart``, may be it help. Also check the file ``/tmp/unicorn.myapp.sock``, does it readable and writeable. – duykhoa Feb 22 '15 at 13:44
  • Now that I see, that file is not there. ls shows only those folders:cache pids sessions sockets. Any hint why that sock is not created? – Ricardo Castañeda Feb 22 '15 at 19:59
  • No, with domain name I don't include the port. It's just mydomain.com. – Ricardo Castañeda Feb 25 '15 at 18:05

2 Answers2

1

Check out this previous answer as it might be the solution to your problem: Nginx cannot find unix socket file with Unicorn (no such file or directory)

The tl;dr version is you might need to create your unicorn socket in a different location. It might be that when you went from being "localhost" to a domain name you are telling the upstream app that you aren't coming from the local filesystem anymore; however, that is conjecture and someone else should chime in.

This post notes that you can't put interprocess communication sockets in /tmp: https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025

Community
  • 1
  • 1
HeadCode
  • 2,770
  • 1
  • 14
  • 26
0

Seems like requires additional information about your environment:

1) namei -lm /tmp/unicorn.myapp.sock - display all permissions of path

2) ps aux | grep nginx - display nginx owner and group

3) ps axu | grep unicorn - display unicorn owner and group

4) Provide value of user statement from /etc/nginx/nginx.conf

Maxim
  • 9,701
  • 5
  • 60
  • 108