Nginx作为静态资源web服务_跨站访问场景配置
跨域访问场景演示
设施准备:两台云服务器 or 创建两台虚拟服务器(VMWare、VirtureBox等)
(1)腾讯云服务器上新增CSRF.html文件
使用JQuery Ajax请求模拟跨域访问:
CSRF.html代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>CSRF 测试</title>
<meta name="keywords" content="" />
<meta name="discription" content="" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.ajax({
type:"GET",
url:"http://120.78.153.144:80/cross_domain.html",
success:
function(result){
$("#div1").html(result);
},
error:
function(result){
alert("跨域失败failed!");
}
}
);
});
});
</script>
</head>
<body>
<h1>CSRF跨站访问测试</h1>
<div id="div1"><h2>click the button to validate crossing domain</h2></div>
<button>获取其他内容</button>
</body>
</html>
(2)阿里云服务器上创建cross_domain.html文件
编辑cross_domain.html文件:
cross_domain.html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>CSRF ????</title>
<meta name="keywords" content="" />
<meta name="discription" content="" />
</script>
</head>
<body>
<h1>Cross Domain Invoke Success!!!!!!!!</h1>
</body>
</html>
(3)阿里云服务器上增加跨域设置
(5)验证跨域访问是否生效
首先访问http://dragonbrother.1.com/CSRF.html
然后点击“check cross domain button”按钮,校验是否支持跨域
(6)如果此时关闭跨域设置,会出现跨域问题
关闭阿里云服务器nginx跨域设置都会出现跨域问题
首先访问http://dragonbrother.1.com/CSRF.html
然后点击“check cross domain button”按钮,校验是否支持跨域