Question

Nginx 502 Bad Gateway simple Rails App in CentOS 7.x

  • Posted on February 4, 2015
  • frontendAsked by frontend

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;
}
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Use

setenforce permissive

and run!