前端开发中使用nginx跨域解决No Access-Control-Allow-Origin header localhost:63342 is not allowed access
来源:互联网 发布:10年前你错过了淘宝 编辑:程序博客网 时间:2024/06/08 00:18
nginx是反向代理服务器,正向代理服务器与反向代理服务器的区别不赘述,有很多好的图片一看便知。
在前端开发时会遇到前端和后台服务器在不同IP上的情况,这是如果直接ajax 远程后台服务器,会报错
Failed to loadhttp://10.100.122.138:8081/qrapp-service/bus/getStationByLine?busLine=1
: No 'Access-Control-Allow-Origin'header is present on the requested resource. Origin 'http://localhost:63342' istherefore not allowed access.
这里介绍使用nginx实现跨域的方法
先画出原理图,在叙述配置方法
需求:在前端ajax中可以访问两个服务器,一个是部署在本机(IP:10.100.122.132)8080端口上的tomcat,一个是部署在局域网上另一台机器(IP:10.100.122.138)8081端口上的tomcat
原理图:
nginx配置文件:
配置两个server
#转发到本地8080端口的配置 server {#监听端口 listen 80;#域名可以有多个,用空格隔开server_name 10.100.122.132; location / {proxy_pass http://10.100.122.132:8080;add_header 'Access-Control-Allow-Origin' 'http://localhost:63342'; ssi on; } }#转发到10.100.122.138 8081端口的配置 server {#监听端口 listen 8082;#域名可以有多个,用空格隔开server_name 10.100.122.132; location /qrapp-service/ { proxy_pass http://10.100.122.138:8081/qrapp-service/;ssi on;add_header 'Access-Control-Allow-Origin' 'http://localhost:63342'; } }
阅读全文
0 0
- 前端开发中使用nginx跨域解决No Access-Control-Allow-Origin header localhost:63342 is not allowed access
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin
- Origin null is not allowed by Access-Control-Allow-Origin.
- Origin null is not allowed by Access-Control-Allow-Origin
- Allow No 'Access-Control-Allow-Origin' header is present
- XMLHttpRequest cannot load http://localhost:3000/. No 'Access-Control-Allow-Origin' header is presen
- 跨域问题:No 'Access-Control-Allow-Origin' header is present on the requested resource.
- js跨域访问,No ‘Access-Control-Allow-Origin‘ header is present on
- js跨域访问,No ‘Access-Control-Allow-Origin‘ header is present on
- ajax跨域请求:No 'Access-Control-Allow-Origin' header is present on the requested resource
- js跨域访问,no 'access-control-allow-origin' header is present on the requested resource
- No 'Access-Control-Allow-Origin' header is present on the requested resource.ajax跨域请求
- 跨域问题:“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- 在当地使用Chrome中调试ajax时提示Origin null is not allowed by Access-Control-Allow-Origin
- chrome发起跨域ajax请求遇到 Origin null is not allowed by Access-Control-Allow-Origin 一解
- No 'Access-Control-Allow-Origin' header is present on the requested resource. 报错解决。
- 解决“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- php创建多级目录完整封装类操作
- 木兰词·拟古决绝词柬友
- C++中引用&的相关知识
- 彩色的man pages,让你寻找帮助时也赏心悦目
- ANSI Common Lisp译本笔记3
- 前端开发中使用nginx跨域解决No Access-Control-Allow-Origin header localhost:63342 is not allowed access
- springcloud学习期间的问题
- “SSL peer certificate or SSH remote key was not OK”的分析和解决
- 3D目标识别---局部特征描述子介绍
- GNU gettext utilities
- Android性能优化之谈谈SparseArray,SparseBooleanArray和SparseIntArray
- JAVA 内存可见性
- 单例模式:Singleton Pattern
- freemarker之常用语法