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?