Assuming that you use it as a reverse proxy, I think you can do something similar with NGINX by mixing these guides:
https://stackoverflow.com/questions/3542149/check-the-existence-of-a-session-nginx
https://stackoverflow.com/questions/18970620/nginx-reject-request-if-header-is-not-present-or-wrong
https://stackoverflow.com/questions/11461497/nginx-moving-site-to-new-domain