I have a setup where users are supposed to send requests to A.com. Requests are sent to a CDN which further sends request to A-reader.com, and A-reader routes the request to nginx.
I want A-reader to be accessible only via CDN, so, the aim is to block any request where original request url is not A.com. If any user types A-reader.com/<anything>
in browser address bar, requests should be blocked at nginx
Is this possible?
答案 0 :(得分:1)
是 - 您可以使用nginx http referrer模块 - http://nginx.org/en/docs/http/ngx_http_referer_module.html
在您的情况下,由于您只想允许A.com,配置应该类似于:
valid_referers *.A.com;
if ($invalid_referer) {
return 403;
}
您必须自定义有效的引荐列表以匹配您的域名。
或者,您可以在$ http_referer上进行正则表达式匹配:
if ($http_referer ~* (babes|click|diamond|forsale|girl|jewelry|love|nudit|poker|porn))
{ return 403; }
(https://calomel.org/nginx.html来自How to block referral spam using Nginx?的HTTP referer)