请问 Nginx 怎么添加 CORS 白名单?

155 天前
 whereFly

比如 a.com 下的图片、js 文件等等,只允许 b.comc.com 调用。 其他域名调用的话就显示 404 或者 403 。

2369 次点击
所在节点    NGINX
13 条回复
Chaidu
155 天前
你根本不知道 CORS 是什么意思!
Chaidu
155 天前
以后有问题去问 AI 就行,不要发帖。问题:Nginx 防盗链
wu00
155 天前
Access-Control-Allow-Origin
wzhaoyang
155 天前
img 、js 不存在跨域
zx9481
155 天前
location /images/ {
valid_referers none blocked www.yourdomain.com yourdomain.com;
if ($invalid_referer) {
return 403; # 返回 403 Forbidden 错误
# 或者可以重定向到特定的图片或页面
# return 302 http://www.yourdomain.com/blocked.png;
}
}
paopjian
155 天前
没啥用, 想用你的东西再不行拿反代拉, 你资源真重要就得走登录控制
duzhuo
155 天前
@paopjian 确实,就算登录控制之后日志也得存好
hackroad
155 天前
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
}
}
lisongeee
155 天前
把账号密码私钥给我,我开 ssh 上去免费给你弄
wangtian2020
155 天前
跨域是指,接口没带 CORS 跨域返回头,你的浏览器认为自己不配访问。postman 调用接口是能拿到东西的。
防盗链是指,NGINX 觉得对方的请求头有问题不配拿到任何东西。
YeatsOnce
155 天前
@lisongeee #9 127.0.0.1:22 , root/password123 。谢谢老哥
daimaosix
155 天前
开 ssh 我上去看看
yassinezhang
155 天前
跨域是针对浏览器的名词,只存在于浏览器,正如上面老哥说的,防盗链一行命令就能加,后端程序里现在也有 CORS 插件很方便就能引入。但也仅仅局限于浏览器,

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1122559

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX