From 2677c7ecc1e7ec7a3c4caded7f2e60b94309500d Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Thu, 17 Aug 2023 20:42:17 +0100 Subject: [PATCH] Cantaloupe reverse proxy using resolver --- nginx-vhost.conf | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/nginx-vhost.conf b/nginx-vhost.conf index 579eee4..3fc58d4 100644 --- a/nginx-vhost.conf +++ b/nginx-vhost.conf @@ -1,3 +1,6 @@ +# Set the resolver required by nginx for reverse-proxy lookups when using variables +resolver 9.9.9.9:53; # TODO: Change this to internal IA resolver + server { listen 8080; location / { @@ -11,22 +14,23 @@ server { alias /app/iiify/static; } - location ~ /iiif/image/([23])/(.*)$ { - rewrite ^ $request_uri; - rewrite ^/iiif/image/(2|3)/(.*)$ $2; - add_header 'Access-Control-Allow-Origin' '*' always; - add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, PATCH, DELETE' always; - add_header 'Access-Control-Expose-Headers' '*' always; - return 302 https://services-ia-iiif-cantaloupe-experiment.dev.archive.org/iiif/$1/$2; - } + location ~ /image/iiif/([23])/(.*)$ { + rewrite ^ $request_uri; # Replace nginx $uri with the unescaped version + rewrite ^/image/iiif/(2|3)/(.*)$ /iiif/$1/$2 break; # capture and reformat the URI + + # Settings to ensure Cantaloupe creates the right ids + # https://cantaloupe-project.github.io/manual/5.0/deployment.html#Reverse-Proxying + proxy_set_header X-Forwarded-Host iiif.archive.org; + proxy_set_header X-Forwarded-Path /image; + proxy_set_header X-Forwarded-For $remote_addr; - location ~ /iiif/image/(.*)$ { - rewrite ^ $request_uri; - rewrite ^/iiif/image/(.*)$ $1; + # CORS add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, PUT, PATCH, DELETE' always; add_header 'Access-Control-Expose-Headers' '*' always; - return 302 https://services-ia-iiif-cantaloupe-experiment.dev.archive.org/iiif/3/$1; + + # Reverse proxy with the variables captured above + proxy_pass https://cantaloupe.prod.archive.org/iiif/$1/$2; } }