当前位置:网站首页>实现跨域的几种方式
实现跨域的几种方式
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;
}
}
}
边栏推荐
- 分布式和集群
- [Software Exam System Architect] Software Architecture Design ③ Domain-Specific Software Architecture (DSSA)
- 【过一下8】全连接神经网络 视频 笔记
- Redis - 13. Development Specifications
- Flutter 父子组件如何都能收到点击事件
- 第二讲 Linear Model 线性模型
- 类的底层机制
- Difference between for..in and for..of
- 『递归』递归概念与典型实例
- Convert the paper official seal in the form of a photo into an electronic official seal (no need to download ps)
猜你喜欢

RL reinforcement learning summary (1)

SQL(一) —— 增删改查

Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法

【练一下1】糖尿病遗传风险检测挑战赛 【讯飞开放平台】

Database experiment five backup and recovery

The underlying mechanism of the class

How can Flutter parent and child components receive click events

Mesos学习

vscode+pytorch use experience record (personal record + irregular update)

The role of DataContext in WPF
随机推荐
2023 International Conference on Information and Communication Engineering (JCICE 2023)
位运算符与逻辑运算符的区别
entry point injection
Excel Paint
Flutter learning 2-dart learning
Detailed Explanation of Redis Sentinel Mode Configuration File
2022 Hangzhou Electric Multi-School 1st Session 01
After controlling the export file in MySQL, it becomes \N. Is there any solution?
ES6 生成器
【技能】长期更新
Structured light 3D reconstruction (1) Striped structured light 3D reconstruction
MySQL Foundation (1) - Basic Cognition and Operation
UVA10827
[Software Exam System Architect] Software Architecture Design ③ Domain-Specific Software Architecture (DSSA)
DOM and its applications
redis 持久化
Database experiment five backup and recovery
ESP32 485 Illuminance
结构光三维重建(一)条纹结构光三维重建
Reverse theory knowledge 4