DCAS handbook

Nginx examples

nginx.conf

http {
	# Omitted

	# Gzip Settings

	gzip on;

	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 6;
	gzip_buffers 16 8k;
	gzip_http_version 1.1;
	gzip_min_length 256;
	gzip_types
	  application/atom+xml
	  application/geo+json
	  application/javascript
	  application/x-javascript
	  application/json
	  application/ld+json
	  application/manifest+json
	  application/rdf+xml
	  application/rss+xml
	  application/xhtml+xml
	  application/xml
	  font/eot
	  font/otf
	  font/ttf
	  image/svg+xml
	  text/css
	  text/javascript
	  text/plain
	  text/xml;

	# Caching

	proxy_cache_path /var/lib/nginx/cache
		keys_zone=mycache:10m
		levels=1:2;
	proxy_cache_key "$host$request_uri";

  # Omitted
}

main config

server {
  ...

  location / {

    proxy_pass ...;

    proxy_buffering on;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header "Connection" "";
    proxy_cache mycache;

    # Cache status debugging
    add_header X-Cache-Status $upstream_cache_status;

    # Api endpoint has to be handled differently
    location /api/ {
      proxy_pass .../api/;

      # Disable caching
      proxy_cache off;

      # Increase request body size
      client_max_body_size 12M;

      # Add "response time" header (for debug)
      add_header X-Time '$request_time';
    }

  }
}

server {
  server_name ...;
  listen 80;

  if ($host = ...) {
      return 301 https://$host$request_uri;
  }

  return 404;
}

cdn config

server {
  ...

  location / {

    proxy_pass ...;
    proxy_http_version 1.1;
    proxy_set_header "Connection" "";
    proxy_cache mycache;

    # Cache status debugging
    add_header X-Cache-Status $upstream_cache_status;

    # Additionally limit upload size
    client_max_body_size 16M;

  }
}