Cross-domain access control
Cross-domain access
##Why does the browser prohibit cross-domain accessNot safe, prone to CSRF attacks!
How nginx configures cross-domain access
add_header syntaxlocation ~ .*\.(htm|html)$ { add_header access-control-allow-origin *; add_header access-control-allow-methods get,post,put,delete,options; root /opt/app/code; }
Anti-hotlinking
Based on http_referer anti-hotlinking Configuration module
ngx_http_referer_module module is used to prevent requests with invalid values in the "referer" header field from accessing the site. Examplevalid_referers none blocked server_names *.example.com example.* www.example.org/galleries/ ~\.google\.; if ($invalid_referer) { return 403; }
referer_hash_bucket_size syntax
referer_hash_bucket_size size; indicates that the setting is valid The storage size of the reference hash table.
referer_hash_max_size Syntaxreferer_hash_max_size size; means setting the maximum size of the effective referrer hash table .
touch test_referer.html (In the /op/app/code directory)
<html> <head> <meta charset="utf-8"> <title>imooc1</title> </head> <body style="background-color:red;"><br data-filtered="filtered"> <h1>张彪</h1> <img src="http://192.168.1.112/wei.png"/ alt="How to configure Nginx cross-domain access and anti-leeching" > </body> </html>
If the anti-hotlink configuration is not transferred from the www.zhangbiao.com domain name, an error will be reported
location ~ .*\.(jpg|gif|png)$ { valid_referers none blocked www.zhangbiao.com; if ($invalid_referer) { return 403; } root /opt/app/code/images; } location ~ /test_refer.html { root /opt/app/code; }
http://192.168.1.112/test_refer.html
http://www.zhangbiao.com/test_refer.html
The above is the detailed content of How to configure Nginx cross-domain access and anti-leeching. For more information, please follow other related articles on the PHP Chinese website!