We use combination of those headers(config for nginx):
# Before enabling Strict-Transport-Security headers please read into this topic first.
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
Be careful, depending on your application those might break your website. Read here before implementing them https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
EDIT: As pointed those will not outright prevent proxing trough foreign domain, you should also set the additional step of serving requests that are only addressing you via the correct host name:
Change your default nginx.conf to something like:
server {
listen 443 ssl http2;
server_name _;
### Set dummy certs
ssl on;
ssl_certificate /usr/local/etc/ssl/dummy.crt;
ssl_certificate_key /usr/local/etc/ssl/dummy.key;
ssl_dhparam /usr/local/etc/ssl/dhparam.pem;
### Block all, allow only vhosts on this server
location / {
limit_req zone=one burst=10 nodelay;
deny all;
return 418 "I'm a teapot"; # Just for the fun of it
}
}
### Virtual Hosting
include /usr/local/etc/nginx/conf.d/*.conf;
}
Now in /usr/local/etc/nginx/conf.d/ (FreeBSD paths, adjust to your distro) create a domain_name.conf that contains settings for your actual site and set the accepted server_name for it:
server_name www.example.com example.com;
That combined with the protection headers will stop most of the attacks of this kind.
However a really clever jackass can spoof the Host header on his reverse proxy as well.
The only truly working method was https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning however this standard is being deprecated as it was half cooked and quite dangerous to implement.