Skip to content

Instantly share code, notes, and snippets.

@DVG
Created March 18, 2015 14:18
Show Gist options
  • Save DVG/633b2c5246a8515b692c to your computer and use it in GitHub Desktop.
Save DVG/633b2c5246a8515b692c to your computer and use it in GitHub Desktop.
nginx for sinatra
# this sets the user nginx will run as,
#and the number of worker processes
user nobody nogroup;
worker_processes 1;
# setup where nginx will log errors to
# and where the nginx process id resides
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# set to on if you have more than 1 worker_processes
accept_mutex off;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
# use the kernel sendfile
sendfile on;
# prepend http headers before sendfile()
tcp_nopush on;
keepalive_timeout 5;
tcp_nodelay on;
gzip on;
gzip_vary on;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml image/x-icon;
# use the socket we configured in our unicorn.rb
upstream unicorn_server {
server unix:/path/to/app/tmp/sockets/unicorn.sock
fail_timeout=0;
}
# configure the virtual host
server {
# replace with your domain name
server_name my-sinatra-app.com;
# replace this with your static Sinatra app files, root + public
root /path/to/app/public;
# port to listen for requests on
listen 80;
# maximum accepted body size of client request
client_max_body_size 4G;
# the server will close connections after this time
keepalive_timeout 5;
location / {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# pass to the upstream unicorn server mentioned above
proxy_pass http://unicorn_server;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment