Nginx and Ruby3/Puma with Sinatra

ZeroPivot's photo
·Jan 3, 2021·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

Just some quick notes on how to use nginx with Ruby/Puma, and SSL, after spending an entire day debugging.

Here is what I am currently using:

Ruby 3.0.0 on WSL2 with Ubuntu 20.04LTS; the app get pushed to servers on, using the same distro now, and was the reason I wrote this little journal.

Given that you are already using Rails or Sinatra with Ruby 3.0.0, preferably on the latest distribution of Ubuntu

service nginx start to see if NGINX is working correctly

service nginx restart

If not:

sudo apt install nginx

Here is my file for NGINX, it goes in /etc/nginx/nginx.conf:

user root;
worker_processes auto;
pid /run/;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    #multi_accept on;

http {

upstream app { server unix://root/comicman-remote-modular/config/puma.sock; }

server {

        root /root/app_location/public;
    location / {
        proxy_pass http://app;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwaeded-Host '';
        proxy_set_header X-Forwarded-Proto $scheme;

    #error_page 500 502 503 504 /500.html;
    #error_page 404 /404.html;
    client_max_body_size 4G;
    keepalive_timeout 60;


    # Basic Settings

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # SSL Settings

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    # Logging Settings

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Virtual Host Configs

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

server {
        listen 80;
    listen [::]:80;


This nginx file for the puma proxy requires modification.

Also, comment out everything in the files in /etc/nginx/sites-available, or it will try defaulting to their html pages.

Then, in /usr/local/nginx/html, delete everything; you don't need html pages to send instead of the Proxy.

If you want SSL, follow the directions at: -- Let's Encrypt and Certbot will automate updating and providing you with SSL certificates.

More to come, mostly updates.

Share this