Skip to content

Commit

Permalink
Merge pull request #20 from europeana/Ea-3235_addingResolver
Browse files Browse the repository at this point in the history
EA-3235 Override NGINX resolver TTL
  • Loading branch information
P-Ehlert committed Nov 16, 2022
2 parents 01cf42b + b90f990 commit 2fcf65f
Showing 1 changed file with 54 additions and 83 deletions.
137 changes: 54 additions & 83 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,6 @@ http {
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container PORT - 8080

upstream search_api {
keepalive 10;
server {{env "SEARCH_API_HOST"}}:443;
}
upstream thumbnail_api {
keepalive 10;
server {{env "THUMBNAIL_API_HOST"}}:443;
}
upstream oai_record {
keepalive 10;
server {{env "OAI_RECORD_HOST"}}:443;
}
upstream annotation_api {
keepalive 10;
server {{env "ANNOTATION_API_HOST"}}:443;
}
upstream entity_api {
keepalive 10;
server {{env "ENTITY_API_HOST"}}:443;
}

upstream entity_management {
keepalive 10;
server {{env "ENTITY_MANAGEMENT_HOST"}}:443;
}

upstream manifest_api {
keepalive 10;
server {{env "MANIFEST_API_HOST"}}:443;
}
upstream fulltext_api {
keepalive 10;
server {{env "FULLTEXT_API_HOST"}}:443;
}
upstream set_api {
keepalive 10;
server {{env "SET_API_HOST"}}:443;
}

upstream recommendation_api {
keepalive 10;
server {{env "RECOMMENDATION_API_HOST"}}:443;
}

server {
listen {{port}};
root public;
Expand All @@ -80,7 +36,22 @@ http {
return 301 https://$host$request_uri;
}

resolver {{env "RESOLVER_ADDRESS"}};
# "upstream" servers do not use resolver settings by default (paid option),
# so we proxy directly to the urls
set $search_api {{env "SEARCH_API_HOST"}};
set $thumbnail_api {{env "THUMBNAIL_API_HOST"}};
set $oai_record {{env "OAI_RECORD_HOST"}};
set $annotation_api {{env "ANNOTATION_API_HOST"}};
set $entity_api {{env "ENTITY_API_HOST"}};
set $entity_management {{env "ENTITY_MANAGEMENT_HOST"}};
set $manifest_api {{env "MANIFEST_API_HOST"}};
set $set_api {{env "SET_API_HOST"}};
set $fulltext_api {{env "FULLTEXT_API_HOST"}};
set $recommendation_api {{env "RECOMMENDATION_API_HOST"}};


# Override TTL from responses; cache IP addresses for 5 minutes
resolver {{env "RESOLVER_ADDRESS"}} valid=5m;

add_header Link "<http://creativecommons.org/publicdomain/zero/1.0/>;rel=license";

Expand All @@ -105,8 +76,8 @@ http {
# Not sure why we have this rule and if it's still useful.
location ~ ^/api/(.*) {
rewrite ^/api/(.*)$ /api/$1 break;
proxy_set_header Host {{env "SEARCH_API_HOST"}};
proxy_pass https://search_api;
proxy_set_header Host $search_api;
proxy_pass https://$search_api;
}


Expand Down Expand Up @@ -141,46 +112,46 @@ http {

# Recommendation API (alternative path, has to be defined before Search & Record)
location ~ ^/record/(v2/)?(.*)/recommend {
proxy_set_header Host {{env "RECOMMENDATION_API_HOST"}};
proxy_pass https://recommendation_api/recommend/record/$2$is_args$args;
proxy_set_header Host $recommendation_api;
proxy_pass https://$recommendation_api/recommend/record/$2$is_args$args;
}

# Search API
location ~ ^/record/(v2/)?(open)?search(.*) {
rewrite ^/record/(v2/)?(open)?search(.*)$ /api/v2/$2search$3 break;
proxy_set_header Host {{env "SEARCH_API_HOST"}};
proxy_pass https://search_api;
proxy_set_header Host $search_api;
proxy_pass https://$search_api;
}

# Record API
location ~ ^/record/(v2/)?(.*) {
rewrite ^/record/(v2/)?(.*)$ /api/v2/record/$2 break;
proxy_set_header Host {{env "SEARCH_API_HOST"}};
proxy_pass https://search_api;
proxy_set_header Host $search_api;
proxy_pass https://$search_api;
}

# Always enable CORS for Search & Record API Swagger endpoint (as bug fix)
location = /record/api-docs {
proxy_set_header Host {{env "SEARCH_API_HOST"}};
proxy_set_header Host $search_api;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Origin "*";
proxy_pass https://search_api/api/api-docs;
proxy_pass https://$search_api/api/api-docs;
}

# Thumbnail API v2 (old style)
location = /api/v2/thumbnail-by-url.json {
# Thumbnails are JPEGs; no need to gzip them
gzip off;
proxy_set_header Host {{env "THUMBNAIL_API_HOST"}};
proxy_pass https://thumbnail_api;
proxy_set_header Host $thumbnail_api;
proxy_pass https://$thumbnail_api;
}

# Thumbnail API v2 (new style)
location = /thumbnail/v2/url.json {
# Thumbnails are JPEGs; no need to gzip them
gzip off;
proxy_set_header Host {{env "THUMBNAIL_API_HOST"}};
proxy_pass https://thumbnail_api/api/v2/thumbnail-by-url.json;
proxy_set_header Host $thumbnail_api;
proxy_pass https://$thumbnail_api/api/v2/thumbnail-by-url.json$is_args$args;
}

location ~ /thumbnail/v2/(.*) {
Expand All @@ -192,20 +163,20 @@ http {
location ~ /thumbnail/(v3/)?(.*) {
# Thumbnails are JPEGs; no need to gzip them
gzip off;
proxy_set_header Host {{env "THUMBNAIL_API_HOST"}};
proxy_pass https://thumbnail_api/thumbnail/v3/$2$is_args$args;
proxy_set_header Host $thumbnail_api;
proxy_pass https://$thumbnail_api/thumbnail/v3/$2$is_args$args;
}

# OAI-PMH requests
location = /oai/record {
proxy_set_header Host {{env "OAI_RECORD_HOST"}};
proxy_pass https://oai_record/oai/$is_args$args;
proxy_set_header Host $oai_record;
proxy_pass https://$oai_record/oai/$is_args$args;
}

# OAI-PMH index page
location = /oai/record/ {
proxy_set_header Host {{env "OAI_RECORD_HOST"}};
proxy_pass https://oai_record/index.html;
proxy_set_header Host $oai_record;
proxy_pass https://$oai_record/index.html;
}

# Change all OAI-PMH .shtml form pages to .html
Expand All @@ -215,56 +186,56 @@ http {

# OAI-PMH query forms
location ~ ^/oai/record/(.*)\.html {
proxy_set_header Host {{env "OAI_RECORD_HOST"}};
proxy_pass https://oai_record/$1.html;
proxy_set_header Host $oai_record;
proxy_pass https://$oai_record/$1.html;
}

# Annotation API
location ~ ^/annotation/(.*) {
proxy_set_header Host {{env "ANNOTATION_API_HOST"}};
proxy_pass https://annotation_api/annotation/$1$is_args$args;
proxy_set_header Host $annotation_api;
proxy_pass https://$annotation_api/annotation/$1$is_args$args;
}

# Entity - search, resolve and suggest are routed to Entity API
location ~ ^/entity/(search|suggest|resolve|enrich|stats)(.*) {
proxy_set_header Host {{env "ENTITY_API_HOST"}};
proxy_pass https://entity_api/entity/$1$2$is_args$args;
proxy_set_header Host $entity_api;
proxy_pass https://$entity_api/entity/$1$2$is_args$args;
}

# Entity - all other requests go to Entity Management
location ~ ^/entity/(.*) {
proxy_set_header Host {{env "ENTITY_MANAGEMENT_HOST"}};
proxy_pass https://entity_management/entity/$1$is_args$args;
proxy_set_header Host $entity_management;
proxy_pass https://$entity_management/entity/$1$is_args$args;
}

# Manifest API
location ~ ^/presentation/(.*)/manifest$ {
proxy_set_header Host {{env "MANIFEST_API_HOST"}};
proxy_pass https://manifest_api/presentation/$1/manifest$is_args$args;
proxy_set_header Host $manifest_api;
proxy_pass https://$manifest_api/presentation/$1/manifest$is_args$args;
}

# Fulltext API
location ~ ^/(fulltext|presentation)/(.*) {
proxy_set_header Host {{env "FULLTEXT_API_HOST"}};
proxy_pass https://fulltext_api/presentation/$2$is_args$args;
proxy_set_header Host $fulltext_api;
proxy_pass https://$fulltext_api/presentation/$2$is_args$args;
}

# Recommendation API
location ~ ^/recommend/(.*) {
proxy_set_header Host {{env "RECOMMENDATION_API_HOST"}};
proxy_pass https://recommendation_api/recommend/$1$is_args$args;
proxy_set_header Host $recommendation_api;
proxy_pass https://$recommendation_api/recommend/$1$is_args$args;
}

# Recommendation API (alternative path)
location ~ ^/set/(.*)/recommend {
proxy_set_header Host {{env "RECOMMENDATION_API_HOST"}};
proxy_pass https://recommendation_api/recommend/set/$1$is_args$args;
proxy_set_header Host $recommendation_api;
proxy_pass https://$recommendation_api/recommend/set/$1$is_args$args;
}

# Sets API
location ~ ^/set/(.*) {
proxy_set_header Host {{env "SET_API_HOST"}};
proxy_pass https://set_api/set/$1$is_args$args;
proxy_set_header Host $set_api;
proxy_pass https://$set_api/set/$1$is_args$args;
}

# ----------------------------------------------------------
Expand Down

0 comments on commit 2fcf65f

Please sign in to comment.