Skip to content

Commit b78fc7f

Browse files
authored
Use nginx instead of webrick when hosting on Heroku (#156)
This uses the heroku NGINX buildpack to serve up the static files instead of a ruby process. This is better in prod than webrick, as it is a proper webserver that can handle more than one request at a time. This will do while we sort out Cloudflare buckets etc.
1 parent 78fcf32 commit b78fc7f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Procfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: ruby -run -e httpd -- -p $PORT build/
1+
web: bin/start-nginx-solo

app.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"buildpacks": [
99
{
1010
"url": "heroku/nodejs"
11+
},
12+
{
13+
"url": "https://github.com/heroku/heroku-buildpack-nginx"
1114
}
1215
]
1316
}

config/nginx.conf.erb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
daemon off;
2+
# Heroku dynos have at least 4 cores.
3+
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
4+
5+
events {
6+
use epoll;
7+
accept_mutex on;
8+
worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
9+
}
10+
11+
http {
12+
gzip on;
13+
gzip_comp_level 2;
14+
gzip_min_length 512;
15+
gzip_proxied any; # Heroku router sends Via header
16+
17+
server_tokens off;
18+
19+
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
20+
access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
21+
error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;
22+
23+
24+
include mime.types;
25+
default_type application/octet-stream;
26+
sendfile on;
27+
28+
# Must read the body in 5 seconds.
29+
client_body_timeout <%= ENV['NGINX_CLIENT_BODY_TIMEOUT'] || 5 %>;
30+
31+
server {
32+
listen <%= ENV["PORT"] %>;
33+
server_name _;
34+
keepalive_timeout 5;
35+
client_max_body_size <%= ENV['NGINX_CLIENT_MAX_BODY_SIZE'] || 1 %>M;
36+
37+
root /app/build; # path to your app
38+
}
39+
}

0 commit comments

Comments
 (0)