Question
Nginx 502 Bad Gateway simple Rails App in CentOS 7.x
In CentOS 7.x I’ve installed a Rails app which I can access through [ip]:8080. It works.
But when I set the domain name as a server_name (instead of localhost) I get a 502 Bad Gateway problem.
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;
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;
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
Are you seeing anything in your Nginx error logs?
/var/log/nginx/error.log
Generally, a 502 error means that there is a problem with the connection between the app and the proxy server. Is the app using/tmp/unicorn.myapp.sock
to communicate, does it actually exist?Hi @asb.
No, unicorn.myapp.sock seems to be missing.
This is what my
/var/log/nginx/error.log
shows:(sorry for all this pasted code)
What confuses me is that when I use the ip, the Rails application runs, but it doesn’t when domain name is set.