nginx屏蔽js等文件直接訪問
應公司安全測試要求,webpack打包后的js文件不能直接在瀏覽器打開。
解決方法:通過nginx配置文件過濾,跳轉到403頁面,代碼如下:
location / {
set $flag 0;
if ($request_uri ~ ".js" ){
set $flag "${flag}1";
}
if ($http_referer = ''){
set $flag "${flag}1";
}
if ($flag = "011"){
return 403;
}
root /usr/share/nginx/html;
index index.html index.htm;
}
瀏覽器通過如:http://xx.xxx.xxx.xxx/static/js/chunk-ebddbf92.8f856533.js
http://xx.xxx.xxx.xxx/static/js/chunk-e497b420.8e5939b0.js
http://xx.xxx.xxx.xxx/static/js/chunk-bffc6128.0c9c3cda.js
的地址訪問就會跳轉到403 forbidden頁面拉。
作者:張瑞153169
-------------------------------------------
個性簽名:獨學而無友,則孤陋而寡聞。做一個靈魂有趣的人!
如果覺得這篇文章對你有小小的幫助的話,記得在右下角點個“推薦”哦,在此感謝!

浙公網(wǎng)安備 33010602011771號