Skip to content

Instantly share code, notes, and snippets.

@Matrixbirds
Created January 15, 2017 06:56
Show Gist options
  • Select an option

  • Save Matrixbirds/9f1f202003e00010e9ce7cc4585508c8 to your computer and use it in GitHub Desktop.

Select an option

Save Matrixbirds/9f1f202003e00010e9ce7cc4585508c8 to your computer and use it in GitHub Desktop.
nginx fcgi ruby rack app config examples
require 'bundler'
Bundler.require(:default, ENV.fetch("RACK_ENV"))
SOCK_FILEPATH = "./rack.sock"
Rack::Handler::FastCGI.run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["It Works"]] }, File: SOCK_FILEPATH
server {
listen 8080;
server_name localhost;
access_log logs/host.access.log main;
location / {
fastcgi_pass unix:/${APP_SOCK_FILEPATH}.sock; # APP_SOCK_FILE_PATH is your rack app unix-domain-sock filepath
}
error_page 404 /404.html;
redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

Notice

  • this gists is tested base nginx/1.10.1, rack 2.0.1
  • rack just provider many handler, use fcgi u should install it's deps by self

Install FCGI For Ubuntu User

  1. sudo apt-get install libfcgi-dev
  2. gem install fcgi # deps libfcgi

rackup

rackup config.ru

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