Created
April 4, 2018 00:47
-
-
Save keidrun/1193c02cd46fa23a0cab05124394a233 to your computer and use it in GitHub Desktop.
nginx.conf for Heroku
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; # For Docker | |
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>; # For Heroku | |
load_module modules/ngx_http_geoip_module.so; # GeoIP | |
events { | |
worker_connections 1024; | |
multi_accept on; | |
use epoll; | |
} | |
http { | |
charset utf-8; | |
sendfile on; | |
tcp_nopush on; | |
server_tokens off; | |
keepalive_timeout 65s; | |
gzip on; | |
gzip_min_length 100; | |
gzip_comp_level 3; | |
gzip_types text/css; | |
gzip_types text/javascript; | |
gzip_disable "msie6"; | |
include mime.types; | |
default_type application/octet-stream; | |
open_file_cache max=1000 inactive=20s; | |
open_file_cache_valid 30s; | |
open_file_cache_min_uses 2; | |
open_file_cache_errors on; | |
client_body_buffer_size 16k; | |
client_header_buffer_size 1k; | |
client_max_body_size 8m; | |
large_client_header_buffers 2 1k; | |
client_body_timeout 5; # For Heroku | |
# GeoIP | |
geoip_country /etc/nginx/geoip/GeoIP.dat; | |
geoip_city /etc/nginx/geoip/GeoLiteCity.dat; | |
# Logs | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for" ' | |
'"$request_body"'; | |
access_log logs/access.log main; | |
error_log logs/error.log warn; | |
upstream heroku_app { | |
server <%= ENV["HEROKU_APP_DOMAIN"] %>; | |
} | |
server{ | |
listen <%= ENV["PORT"] %>; | |
server_name _; | |
# Common headers | |
add_header X-Frame-Options SAMEORIGIN; | |
location ^~ / { | |
proxy_pass http://heroku_app; | |
proxy_redirect off; | |
proxy_set_header Host <%= ENV["HEROKU_APP_HOST"] %>; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Host $http_host; | |
proxy_set_header X-Forwarded-Server $http_host; | |
proxy_set_header Connection ''; | |
proxy_http_version 1.1; | |
} | |
location ~* \.(css|js|jpg|png|gif)$ { | |
access_log off; | |
expires 1M; | |
add_header Pragma public; | |
add_header Cache-Control public; | |
add_header Vary Accept-Encoding; | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /sites/public; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment