Last active
February 9, 2018 00:17
-
-
Save tarla/2e65c739614a5b4a34d67d715d26f3b7 to your computer and use it in GitHub Desktop.
nginx config file for Heroku nginx buildpack
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
daemon off; | |
#Heroku dynos have at least 4 cores. | |
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>; | |
events { | |
use epoll; | |
accept_mutex on; | |
worker_connections 1024; | |
} | |
http { | |
gzip on; | |
gzip_comp_level 2; | |
gzip_min_length 512; | |
server_tokens off; | |
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id'; | |
access_log logs/nginx/access.log l2met; | |
error_log logs/nginx/error.log; | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
#Must read the body in 5 seconds. | |
client_body_timeout 5; | |
upstream app_server { | |
server unix:/tmp/nginx.socket fail_timeout=0; | |
} | |
# Expires map | |
map $sent_http_content_type $expires { | |
default off; | |
text/html epoch; | |
text/css max; | |
text/plain max; | |
application/javascript max; | |
~image/ max; | |
} | |
server { | |
listen <%= ENV["PORT"] %>; | |
server_name _; | |
keepalive_timeout 5; | |
expires $expires; | |
location / { | |
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; | |
} | |
} | |
} |
puma.rb
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 4 }
threads threads_count, threads_count
environment ENV.fetch("RAILS_ENV") { "development" }
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
FileUtils.touch('/tmp/app-initialized')
end
bind "unix:///tmp/nginx.socket"
plugin :tmp_restart
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heroku Buildpack URL:
https://github.com/heroku/heroku-buildpack-nginx
Nginx config file path:
config/nginx.conf.erb
Procfile:
web: bin/start-nginx bundle exec puma -e ${RACK_ENV:-development}