利用Nginx进行来源地址拦截,只要来源地址符合原资源地址,则可以访问,否则返回403状态码或者非法图标
1、目录展示
2、A项目下jsp页面
<%--
Created by IntelliJ IDEA.
User: zheng
Date: 2020/2/10
Time: 18:08
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="Java" %>
<html>
<head>
<title>Nginx防盗链</title>
</head>
<body>
<img src="http://www.a.com:8080/A/img/1.png">
</body>
</html>
3、B项目下jsp页面
<%--
Created by IntelliJ IDEA.
User: zheng
Date: 2020/2/10
Time: 15:01
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Nginx解决跨域问题</title>
</head>
<body>
数据:<input type="text" name="username" id="username"/>
<input type="button" id="button" value="请求"/>
<hr/>
<img src="http://www.znzn.com/A/img/1.png">
</body>
</html>
4、修改nginx.conf文件、重启Nginx
5、A项目访问效果
6、效果展示