Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx, Sinatra, and Puma.
#!/usr/bin/env ruby
require 'sinatra'
configure {
set :server, :puma
}
class Pumatra < Sinatra::Base
get '/' do
return 'It works!'
end
run! if app_file == $0
end
bundle install --path vendor/bundle
mkdir -p tmp/puma
bundle exec puma --config config/puma.rb
#!/usr/bin/env ruby
require './app'
run Pumatra
source :rubygems
gem "puma"
gem "sinatra"
upstream app {
server unix:///appdir/tmp/puma/socket;
}
server {
listen 80;
server_name app.com;
root /appdir/public;
access_log /appdir/log/nginx.access.log;
error_log /appdir/log/nginx.error.log info;
location / {
try_files $uri @puma;
}
location @puma {
include proxy_params;
proxy_pass http://app;
}
}
root = "#{Dir.getwd}"
bind "unix://#{root}/tmp/puma/socket"
pidfile "#{root}/tmp/puma/pid"
state_path "#{root}/tmp/puma/state"
rackup "#{root}/config.ru"
threads 4, 8
activate_control_app
@mikeyhill

This comment has been minimized.

Copy link

@mikeyhill mikeyhill commented Oct 10, 2013

not to anyone that references this:

upstream app {
server unix:///appdir/tmp/puma/socket;
}

should be:

upstream puma {
server unix:///appdir/tmp/puma/socket;
}

@gitconfig

This comment has been minimized.

Copy link

@gitconfig gitconfig commented Oct 17, 2013

@ctalkington Thanks!

@mikeyhill the original works for me.

@dznet

This comment has been minimized.

Copy link

@dznet dznet commented Jan 31, 2017

@mikeyhill, you should be use a simular name in 'upstream' and in 'proxy_pass'
for example:

upstream your_app_name {
server unix:///appdir/tmp/puma/socket;
}
......
location @puma {
include proxy_params;
proxy_pass http://your_app_name;
}

@giuseb

This comment has been minimized.

Copy link

@giuseb giuseb commented Mar 15, 2020

If you are getting an error at the line include proxy_params; you may want to see this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment