Skip to content

Instantly share code, notes, and snippets.

@arbakker
Last active December 15, 2021 16:23
Show Gist options
  • Save arbakker/8ee3a90feff7fbf74cad707c445f4b35 to your computer and use it in GitHub Desktop.
Save arbakker/8ee3a90feff7fbf74cad707c445f4b35 to your computer and use it in GitHub Desktop.
Minimal nginx config to reverse proxy a INSPIRE Atom service #nginx #ngrok #atom

Reverse Proxy a INSPIRE Atom service with NGINX

Minimal NGINX config to reverse proxy a INSPIRE Atom service and manipulate the response body as well as response headers. Intented for debugging purposes.

Start the NGINX reverse proxy:

docker run --name mynginx1 -p 8282:80 -d -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf anroe/nginx-headers-more

To serve out the proxied INSPIRE Atom service on a public url use ngrok (also substitute a working ngrok url in the nginx conf):

ngrok http 8282
server {
listen 80;
listen [::]:80;
server_name localhost;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /.*xml$ {
proxy_pass https://service.pdok.nl;
proxy_set_header X_FORWARDED_PROTO https;
proxy_hide_header Content-Type;
more_set_headers "Content-Type: application/atom+xml";
sub_filter_types *; # match all, otherwise does not seem to work in combination with proxy_hide_header
sub_filter 'https://service.pdok.nl' 'https://ed7e-143-177-33-177.ngrok.io' ;
sub_filter 'https://www.nationaalgeoregister.nl' 'https://ngr.acceptatie.nationaalgeoregister.nl';
sub_filter '<?xml-stylesheet href="https://service.pdok.nl/atom/style/style.xsl" type="text/xsl" media="screen"?>\n' '';
sub_filter_once off;
}
location ~ / {
proxy_pass https://service.pdok.nl;
proxy_set_header X_FORWARDED_PROTO https;
sub_filter_types text/xml application/xml;
sub_filter 'https://service.pdok.nl' 'http://localhost' ;
sub_filter_once off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment