Skip to content

Instantly share code, notes, and snippets.

@sanderpick
Created February 27, 2018 23:54
Show Gist options
  • Save sanderpick/bead03b36712f292a3ddcd657d6afe65 to your computer and use it in GitHub Desktop.
Save sanderpick/bead03b36712f292a3ddcd657d6afe65 to your computer and use it in GitHub Desktop.
nginx config files for an ipfs-cluster peer gateway on Amazon Linux.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
expires $expires;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
# most people include something like this. don't.
# check your default nginx.conf, it's already covered in a much better way.
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# compress proxied requests too.
# it doesn't actually matter if the request is proxied, we still want it compressed.
gzip_proxied any;
# a pretty comprehensive list of content mime types that we want to compress
# there's a lot of repetition here because different applications might use different
# (and possibly non-standard) types. we don't really care, we still want them included
# don't include text/html -- it is always included anyway
gzip_types
text/css
text/plain
text/javascript
application/javascript
application/json
application/x-javascript
application/xml
application/xml+rss
application/xhtml+xml
application/x-font-ttf
application/x-font-opentype
application/vnd.ms-fontobject
image/svg+xml
image/x-icon
application/rss+xml
application/atom_xml;
# increase the compression level, at the expense of additional CPU
# cpu cycles are cheap virtually everywhere now, bandwidth not nearly as much
gzip_comp_level 9;
# the default is to gzip only HTTP 1.1 requests
# we want to gzip http 1.0 requests, too, so lower the level required
gzip_http_version 1.0;
# set the Vary: Accept-Encoding header to force proxies to store compressed and uncompressed versions
# per the nginx docs, a bug in IE 4 - 6 will cause them to not cache anything with this on
# most people aren't going to care about ie 6 anymore, but keep that in mind
gzip_vary on;
# increase the size of the buffers which hold responses to make sure larger content can be compressed too
# this means there are 16 buffers and they can each hold 8k
# if you serve a lot of ridiculously large text (like combined CSS) you might consider upping this slightly
gzip_buffers 16 8k;
# up the minimum length a little to account for gzip overhead
# this means anything smaller than 50 bytes won't be compressed.
# the default is 20 bytes, which is sooo tiny it's a waste to compress
gzip_min_length 50;
@sanderpick
Copy link
Author

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