Nginx and Ruby3/Puma with Sinatra

·

3 min read

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 digitalocean.com, 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:

gist.github.com/ZeroPivot/16482047b72d5d801..

user root;
worker_processes auto;
pid /run/nginx.pid;
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 {

    server_name domain.net www.domain.net;
        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 'domain.net';
        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;

    server_name domain.net www.domain.net;
        }
}

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: certbot.eff.org/lets-encrypt/ubuntufocal-ap.. -- Let's Encrypt and Certbot will automate updating and providing you with SSL certificates.


More to come, mostly updates.