nginx里配置跨域
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, GET";
add_header Access-Control-Allow-Headers $http_access_control_request_headers;
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
if ($request_method != OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Credentials "true";
}
我配置nutzwk open api的时候 遇到这个问题。如果使用了反向代理怎么处理呢?
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.40.231:8080' is therefore not allowed access.
原配置
location / {
proxy_pass http://nutz;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
}
}
upstream nutz{
server 127.0.0.1:8080;
keepalive 65;
}
访问的是 80 反向代理到 8080
访问的 443
走https
8080是我本机开发环境。
我在开发环境一个项目中,调用线上的api接口,然后提示线上的服务,禁止跨域访问
curl -v https://***.***.com/
> GET / HTTP/1.1
> Host: **.***.com
> User-Agent: curl/7.50.3
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: nginx
< Date: Mon, 31 Oct 2016 01:10:56 GMT
< Content-Length: 0
< Connection: keep-alive
< X-Powered-By: nutz/1.r.58 <nutzam.com>
< Location: http://***.****.com/sysadmin
< Strict-Transport-Security: max-age=15768000
我用过滤器的方式解决了。。有时间在配置nginx吧
GlobalsSettingProcessor
ac.getResponse().addHeader("Access-Control-Allow-Origin", "*");
收藏了
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, GET";
add_header Access-Control-Allow-Headers $http_access_control_request_headers;
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
if ($request_method != OPTIONS ) {
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Credentials "true";
}
nginx里配置跨域的更多相关文章
- nginx中配置跨域支持功能
vi /etc/nginx/nginx.conf 加入如下代码 http { ###start#### add_header Access-Control-Allow-Origin *; add ...
- nginx php 配置跨域
我使用的是lnmp一键安装包 在虚拟记住添加 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allo ...
- nginx配置跨域、gzip加速、代理详细讲解
1.配置跨域 这个很简单,直接打开配置nginx.conf ,在http下配置下面三行代码:当然如果你是想某一个虚拟主机下跨域,那就在哪个server下面添加 add_header Access-Co ...
- eclipse加速/Nginx配置跨域代理
下班时间到啦! --下班都是他们的,而我,还是什么都没有. eclipse加速 去掉包含js文件的包的js验证,否则每次启动都需要进行校验(右击项目->properties) Nginx配置跨域 ...
- NGINX: 配置跨域请求
说明: 内容全部来自 SegmentFault Developer Nginx 配置跨域请求 跨域请求失败, nginx 报错: 403 No 'Access-Control-Allow-Origin ...
- 使用Nginx来解决跨域的问题
使用Nginx来解决跨域的问题 nginx的版本:(查看nginx命令: /usr/local/nginx/sbin/nginx -v) nginx/1.4.3 问题是:前端项目域名是 a.xxxx. ...
- 使用nginx实现浏览器跨域请求
跨域访问问题, 相信很多人都遇到过, 并且都用不同的办法去解决过. 方法有很多种, 不一一叙述了. 这里主要使用nginx反向代理来解决跨域问题. 啥是跨域? 假如你是百度开发人员, 在百度页面去请求 ...
- CORS跨域与Nginx反向代理跨域优劣对比
最近写了一些关于前后端分离项目之后,跨域相关方案的基本原理和常见误区的帖子,主要包括CORS和Nginx反向代理.这两种方案项目中都有在用,各有优缺,关于具体使用哪种方案,大家的观点也不大一致,本文主 ...
- nginx 实现 ajax 跨域请求
原文:http://www.nginx.cn/4314.html AJAX从一个域请求另一个域会有跨域的问题.那么如何在nginx上实现ajax跨域请求呢?要在nginx上启用跨域请求,需要添加a ...
随机推荐
- React.js 小书 Lesson24 - PropTypes 和组件参数验证
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson24 转载请注明出处,保留原文链接和作者信息. 我们来了到了一个非常尴尬的章节,很多初学的朋友 ...
- Vim常用插件——前端开发工具系列
作为一名开发者,应该对编辑器之神Vim与神之编辑器Emacs有所耳闻吧.编辑器之战的具体细节有兴趣的童鞋可以google之. Vim最大的特点是打开速度快,功能强大,一旦掌握了其中的命令,编程过程双手 ...
- 有向图和无向图的数组C++实现
源码:https://github.com/cjy513203427/C_Program_Base/tree/master/55.%E5%9B%BE 结点类Noded.h 不需要存储索引 #pragm ...
- 使用idea开发工具,nginx服务部署Extjs6,SpringBoot项目到服务器
编译ExtJs文件 1.输入命令 2.开始编译 3.找到编译后的文件 E:\idea_project\BaiSheng_Model\fin-ui\build\production\Admin 4.将文 ...
- 深入理解JavaScript系列(49):Function模式(上篇)
介绍 本篇主要是介绍Function方面使用的一些技巧(上篇),利用Function特性可以编写出很多非常有意思的代码,本篇主要包括:回调模式.配置对象.返回函数.分布程序.柯里化(Currying) ...
- (转载).NET的五层架构
我们刚开始学习架构的时候,首先会想到分层的概念,分层架构比较经典的是三层架构,那么,什么是三层架构呢?它包括表现层,业务层,数据访问层:而对于一个新手来说,从抽象意义上的三层架构,逻辑上就划分为三个层 ...
- TCP学习(一)
协议分层 可以看到 物理层, 链路层,网络层是所有网络设备共有的, 而传输层, 会话层, 表示层, 应用层 是存在于主机上的 各设备实现的协议层次 IP地址的表示 为什么会出现ip地址?是为了在一 ...
- Nuxt.js学习心得
一.官网 Nuxt.js - Universal Vue.js Applications https://nuxtjs.org/ 二.中文官网 Nuxt.js - Vue.js 通用应用框架 http ...
- JavaScript之如何对客户端进行检测
本文主要是针对各种客户端进行检测,使用了用户代理字符串检测技术,具体代码如下: var client=function() { var engine= { // 呈现引擎 ie: 0, gecko: ...
- unity3d之技能栏冷却
绑定在按钮上的脚本 using UnityEngine; using System.Collections; using UnityEngine.UI; public class CdCover : ...