Nginx配置解决前端跨域问题

前言:

同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响。可以说Web是构建在同源策略基础之上的,浏览器只是针对同源策略的一种实现。所谓同源是指,域名,协议,端口相同。如果非同源,那么在请求数据时,浏览器会在控制台中报一个异常,提示拒绝访问。 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

一、跨域演示

网站A域名:http://192.168.2.126
网站B域名:http://note.t4x.org 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

A网站首页:[调用B网站内容]

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

正常情况下:

同域

同域


跨站情况下:
跨站

跨站


请求头:
请求头

请求头

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

二、解决方法

①:单域名


②:多域名
方法1:文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

http:


server:
文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

方法2:

文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

③:所有域名

多域名配置参考:
1:https://my.oschina.net/yzChen/blog/1573828
2:https://www.cnblogs.com/renjing/p/6394725.html文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/ 文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/basic/nginx-cross-site/

申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!

On this day in past years
June
8
 
Byrd
  • by Published onJune 8, 2019
  • 原文链接:https://note.t4x.org/basic/nginx-cross-site/
匿名

Comment

Anonymous

Slide puzzle verification.