当前位置:网站首页>实现跨域的几种方式
实现跨域的几种方式
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;
}
}
}
边栏推荐
- Reverse theory knowledge 4
- [Decoding tools] Some online tools for Bitcoin
- Error creating bean with name 'configDataContextRefresher' defined in class path resource
- shell函数
- 物理层的接口有哪几个方面的特性?各包含些什么内容?
- Wise Force Deleter强制删除工具
- A blog clears the Redis technology stack
- Using pip to install third-party libraries in Pycharm fails to install: "Non-zero exit code (2)" solution
- Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法
- Dephi reverse tool Dede exports function name MAP and imports it into IDA
猜你喜欢
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
2022杭电多校第一场01
Matplotlib(三)—— 实践
The software design experiment four bridge model experiment
Wise Force Deleter强制删除工具
Database experiment five backup and recovery
SQL(二) —— join窗口函数视图
【过一下12】整整一星期没记录
Structured light 3D reconstruction (1) Striped structured light 3D reconstruction
OFDM Lecture 16 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
随机推荐
day10-字符串作业
pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
Mysql5.7 二进制 部署
2023年信息与通信工程国际会议(JCICE 2023)
【过一下 17】pytorch 改写 keras
vscode+pytorch使用经验记录(个人记录+不定时更新)
Develop a highly fault-tolerant distributed system
数据库 单表查询
The role of the range function
【过一下12】整整一星期没记录
Flutter learning - the beginning
After controlling the export file in MySQL, it becomes \N. Is there any solution?
Detailed Explanation of Redis Sentinel Mode Configuration File
phone call function
Multi-threaded query results, add List collection
Requests the library deployment and common function
OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
Do you use tomatoes to supervise your peers?Add my study room, come on together
DOM及其应用
u-boot in u-boot, dm-pre-reloc