Last active
December 24, 2022 09:27
-
-
Save jesg/25d5b45662341e80f2f2 to your computer and use it in GitHub Desktop.
run sinatra on puma application server behind nginx as a reverse proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /home/<user>/hello-nginx-sinatra/app.rb | |
require 'rubygems' | |
require 'sinatra/base' | |
class App < Sinatra::Application | |
get '/app' do | |
"hello world!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /home/<user>/hello-nginx-sinatra/config.ru | |
require './app' | |
run App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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