Question

502 Nginx and Puma - Ubuntu 14.04

I can’t figure out how to configure properly nginx and puma in my ruby on rails application. When a access it in the browser I get a 502.

I see many similar files:

  • /etc/nginx/nginx.conf
  • /etc/nginx/sites-enabled/myapp
  • /etc/nginx/sites-enabled/myapp_production
  • /etc/nginx/sites-avaliable/myapp_production
  • ~/apps/me/current/config/ngnix.conf

Do I really need that file config/nginx.conf inside my application? How do sockets are supposed to be configured and work? Is there a file among these I mentioned I don`t really need?

If Nginx was working/configured properly it should show this file /var/www/html/index.nginx-debian.html ?

If you need any additional information to be able to help me I’ll gladly provide it. Thanks in advance, Diego


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.

Hi @DiegoBenetti

/etc/nginx/nginx.conf = this is the main Nginx configuration. /etc/nginx/sites-avaliable/myapp_production = this is one of your sites. /etc/nginx/sites-enabled/myapp = this is one of your sites, should be a symlink. /etc/nginx/sites-enabled/myapp_production = this is most likely a symlink. ~/apps/me/current/config/ngnix.conf = I do not know what this is.

The main Nginx configuration should not have any specific website information.

Your websites are normally located in sites-available and then symlinked from sites-enabled, so the sites that are actually active is located in sites-enabled. If that’s confusing, then you can move all files from sites-available to sites-enabled - that means every file will be active.

You should post the ~/apps/me/current/config/ngnix.conf since I don’t know what it is.

If Nginx was configured correctly, then it would normally show content from the root directory specified in one of the site-configurations.

And instead of just the visible error message, let’s have a look in the error log:

tail -30 /var/log/nginx/error.log

upstream puma { server unix:///home/deploy/apps/diegodigital/shared/tmp/sockets/myapp-puma.sock; }

server { listen 80 default_server deferred; server_name my.url;

root /home/deploy/apps/myapp/current/public; access_log /home/deploy/apps/myapp/current/log/nginx.access.log; error_log /home/deploy/apps/myapp/current/log/nginx.error.log info;

location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; }

try_files $uri/index.html $uri @puma; location @puma { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off;

proxy_pass http://puma;

}

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

I tried to follow this digitalOcean tutorial

This tutorial, in the end of 6th step, suggests that nginx.conf file you asked for. The following is mine:

upstream puma {
  server unix:///home/deploy/apps/diegodigital/shared/tmp/sockets/myapp-puma.sock;
}

server {
  listen 80 default_server deferred;
  server_name my.url;

  root /home/deploy/apps/myapp/current/public;
  access_log /home/deploy/apps/myapp/current/log/nginx.access.log;
  error_log /home/deploy/apps/myapp/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

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

I’m totally beginner with nginx, so I can’t tell what is good and right configuration from what it’s not yet. I don’t know what is the nginx default configuration, how it is supposed to work.

I have only one website to launch, if there is more configuration than needed to one, it means I already committed a mistake.