Skip to content

Instantly share code, notes, and snippets.

@jesg
Last active December 24, 2022 09:27
Show Gist options
  • Save jesg/25d5b45662341e80f2f2 to your computer and use it in GitHub Desktop.
Save jesg/25d5b45662341e80f2f2 to your computer and use it in GitHub Desktop.
run sinatra on puma application server behind nginx as a reverse proxy
# /home/<user>/hello-nginx-sinatra/app.rb
require 'rubygems'
require 'sinatra/base'
class App < Sinatra::Application
get '/app' do
"hello world!"
end
end
# /home/<user>/hello-nginx-sinatra/config.ru
require './app'
run App
# replace user with your user
# we use a binstub (https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs)
[Unit]
Description=Hello Sinatra
[Service]
User=<user>
WorkingDirectory=/home/<user>/hello-nginx-sinatra
ExecStart=/home/<user>/.rbenv/versions/jruby-1.7.16/bin/puma -t 2:16 -p 9000
[Install]
WantedBy=multi-user.target
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream app_server {
server 127.0.0.1:9000;
}
server {
listen 80 default deferred;
gzip on;
server_name _;
keepalive_timeout 5;
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_server;
}
}
}
systemctl start nginx
systemctl start hello-sinatra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment