|
upstream load_balancer { |
|
server load.balancer.ip.address; |
|
} |
|
|
|
# set up a map object that will read the `Accept:` header and |
|
# map the values to either v2 or v3 static values. This is used as a cache |
|
# key prefix so that we can set up different caches for either the v2 or v3 |
|
# responses. |
|
map $http_accept $cache_accept_key { |
|
~/.*(?<vthree>presentation/3).*/ "v3"; |
|
~/.*(?<vthree>image/3).*/ "v3"; |
|
default "v2"; |
|
} |
|
|
|
# Virtual host configuration for iiif.bodleian |
|
server { |
|
server_name iiif.hostname.org; |
|
root /var/www/iiif; |
|
|
|
listen 443 ssl http2; |
|
listen [::]:443 ssl http2; |
|
|
|
keepalive_timeout 70; |
|
|
|
ssl_certificate /etc/nginx/ssl/certificate.crt; |
|
ssl_certificate_key /etc/nginx/ssl/certkey.key; |
|
ssl_trusted_certificate /etc/nginx/ssl/certificate.crt; |
|
add_header Strict-Transport-Security "max-age=63072000"; |
|
ssl_stapling on; |
|
ssl_stapling_verify on; |
|
ssl_session_tickets on; |
|
ssl_session_timeout 24h; |
|
ssl_session_cache shared:SSL:100m; |
|
ssl_session_ticket_key /etc/nginx/ssl/ticket.key; |
|
ssl_dhparam /etc/nginx/ssl/dhparam.pem; |
|
ssl_prefer_server_ciphers on; |
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
|
ssl_ciphers "... long list of ciphers ..."; |
|
resolver 8.8.8.8 8.8.4.4; |
|
|
|
|
|
# Ignore all location requests that start with a dot. |
|
# Return 404 to make it look like it's not found (otherwise |
|
# a 403 would say it is there, you just can't access it) |
|
location ~ /\. { |
|
deny all; |
|
access_log off; |
|
return 404; |
|
} |
|
|
|
# For planned service outages, touch /etc/nginx/service.unavailable and this |
|
# host will return 503, which can be detected and automatically shown on |
|
# the service outage page. To resume service, simply delete that file. |
|
if (-f /etc/nginx/service.unavailable) { |
|
return 503; |
|
} |
|
|
|
# Serve a specific page for the 503 error with service outage information. |
|
error_page 503 @custom503; |
|
location @custom503 { |
|
root /var/www/iiif; |
|
rewrite ^(.*)$ /nginx_errors/503.html break; |
|
internal; |
|
} |
|
|
|
# Redirect image API requests without an 'info.json' to the same |
|
# request with an info.json. Matches both URIs with and without |
|
# a trailing slash. |
|
location ~ "^/iiif/image/(?P<iiif>[a-f0-9\-]{36})/?$" { |
|
include allow_origin_wildcard; |
|
return 303 /iiif/image/$iiif/info.json; |
|
} |
|
|
|
# A request for the root of the server will redirect to an 'info.json' |
|
# resource pointing to IIIF resources available on this service. |
|
location ~ "^/?$" { |
|
include allow_origin_wildcard; |
|
return 303 /info.json; |
|
} |
|
|
|
# Forward requests to the load balancers. If the request is an OPTIONS request, |
|
# ensure we serve the data with the appropriate CORS headers and a 204 No Content. |
|
# try_files will allow us to serve static content as first preference, but then |
|
# send the request upstream to our load balancers if it does not match. |
|
location / { |
|
if ($request_method = OPTIONS) { |
|
add_header "Access-Control-Allow-Origin" '*'; |
|
add_header "Access-Control-Allow-Methods" "GET, OPTIONS"; |
|
add_header "Access-Control-Allow-Headers" "Accept,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"; |
|
add_header "Access-Control-Max-Age" 1728000; |
|
add_header "Content-Type" "text/plain; charset=utf-8"; |
|
add_header "Content-Length" 0; |
|
return 204; |
|
} |
|
|
|
include allow_origin_wildcard; |
|
try_files $uri $uri/ @proxy_to_lb; |
|
} |
|
|
|
location @proxy_to_lb { |
|
include proxy_params; |
|
include allow_origin_wildcard; |
|
proxy_set_header X-Real-IP $remote_addr; |
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
proxy_set_header Host $host; |
|
proxy_set_header X-Forwarded-Proto $scheme; |
|
proxy_set_header X-Scheme $scheme; |
|
|
|
proxy_pass http://load_balancer; |
|
proxy_cache iiif; |
|
|
|
# Responses can differ based on original hostname and the IIIF version requested. Read the accept |
|
# header in the $cache_accept_key map and prepend that to the cache key so we can cache IIIF v2 |
|
# and v3 manifests separately. |
|
proxy_cache_key "$cache_accept_key$scheme$host$request_uri"; |
|
add_header X-Cache-Status $upstream_cache_status; |
|
proxy_no_cache $upstream_http_x_bodl_missing; |
|
proxy_cache_bypass $http_pragma; |
|
} |
|
} |
|
|
|
# Automatically forward non-HTTPS to HTTPS. It is important to ensure the CORS |
|
# headers are set appropriately. |
|
server { |
|
listen [::]:80; |
|
listen 80; |
|
server_name iiif.hostname.org; |
|
|
|
location / { |
|
if ($request_method = OPTIONS) { |
|
add_header "Access-Control-Allow-Origin" '*'; |
|
add_header "Access-Control-Allow-Methods" "GET, OPTIONS"; |
|
add_header "Access-Control-Allow-Headers" "Accept,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"; |
|
add_header "Access-Control-Max-Age" 1728000; |
|
add_header "Content-Type" "text/plain; charset=utf-8"; |
|
add_header "Content-Length" 0; |
|
return 204; |
|
} |
|
|
|
include allow_origin_wildcard; |
|
return 301 https://$server_name$request_uri; |
|
} |
|
} |