By DiegoBenetti
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:
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
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!
/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
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.
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; }
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.