当前位置:网站首页>实现跨域的几种方式
实现跨域的几种方式
2022-08-05 05:13:00 【@前端攻城狮】
实现跨域的几种方式
1、CORS
跨域资源共享,在后端的响应头中设置Access-Control-Allow-Origin: *
即可。
2、jsonp
jsonp进行跨域的原理:利用script标签进行网络请求,在本地定义好接收数据的函数,然后通过在请求url中添加参数的方式发送本地函数名,后端通过解析url参数并返回js代码,其中就可包含调用本地函数及传入数据参数的代码。
3、nginx服务器代理
在nginx服务器的默认配置文件nginx.conf中添加:
http {
server {
listen 8088;
#listen [::]:8088;
server_name 47.100.62.167;
#root /usr/share/nginx;
#server_name localhost;
#server_name 192.168.1.3;
location / {
root html;
index index.html index.htm;
# 解决history路由模式下导致的404错误。
try_files $uri $uri/ /index.html;
}
# 为项目配置反向代理
location /api {
proxy_set_header X-Real-IP $remote_addr;
# 需要代理的目标url
proxy_pass http://111.229.37.167/api/;
# 以下配置关闭重定向,让服务端看到用户的IP,而不是nginx服务器的IP
proxy_redirect off;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Nginx-Proxy true;
}
}
}
边栏推荐
- Flutter learning three-Flutter basic structure and principle
- The mall background management system based on Web design and implementation
- Machine Learning (2) - Machine Learning Fundamentals
- 【过一下6】机器视觉视频 【过一下2被挤掉了】
- Flutter TapGestureRecognizer 如何工作
- ESP32 485 Illuminance
- 【技能】长期更新
- 【cesium】Load and locate 3D Tileset
- ES6 生成器
- [Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management
猜你喜欢
Flutter real machine running and simulator running
[cesium] 3D Tileset model is loaded and associated with the model tree
数据库 单表查询
Detailed Explanation of Redis Sentinel Mode Configuration File
OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
Error creating bean with name 'configDataContextRefresher' defined in class path resource
shell函数
2022杭电多校第一场01
SQL(一) —— 增删改查
第二讲 Linear Model 线性模型
随机推荐
Flutter learning 5-integration-packaging-publish
Wise Force Deleter强制删除工具
【过一下 17】pytorch 改写 keras
jvm three heap and stack
判断语句_switch与case
2022杭电多校第一场01
Using pip to install third-party libraries in Pycharm fails to install: "Non-zero exit code (2)" solution
Flutter TapGestureRecognizer 如何工作
A blog clears the Redis technology stack
软件设计 实验四 桥接模式实验
小白一枚各位大牛轻虐虐
RL强化学习总结(一)
What are the characteristics of the interface of the physical layer?What does each contain?
[Decoding tools] Some online tools for Bitcoin
[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
UVA10827
Algorithms - ones and zeros (Kotlin)
【过一下6】机器视觉视频 【过一下2被挤掉了】
有用番茄来监督自己的同道中人吗?加一下我的自习室,一起加油
位运算符与逻辑运算符的区别