发布于 881天前  作者 wendal  1404 次浏览  复制  上一个帖子  下一个帖子
 标签: 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";
}
14 回复

我配置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;
}

访问的是8080?? 不是nginx的80?

访问的是 80 反向代理到 8080

访问的 443

但这里报的是8080呢, Chrome控制台看看请求到哪里去了

8080是我本机开发环境。

我在开发环境一个项目中,调用线上的api接口,然后提示线上的服务,禁止跨域访问

那,我写的那段代码,你贴在nginx.conf的什么地方了?

@wendal 在location /{} 里面

来自炫酷的 NutzCN

执行一下curl,贴一下头部的输出

curl -v http://xxx.x.x..x.x/yyyyy

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";
}

最新文章

  1. 【转载】 ionic 的 下拉刷新 与 上拉加载
  2. Maven 初学(一)基本概念
  3. [转]Web Service Authentication
  4. xxx_cast类型转换
  5. NVMe 图解
  6. 为Delphi程序增加UAC功能(每个步骤都很详细)
  7. KafkaOffsetMonitor
  8. MVC5+EF6 入门
  9. CSS 常用样式 提高网页编写速度
  10. hdu 2196 Computer(树形DP经典)
  11. robotframework2.8.7日志输出List乱码
  12. 设计模式のPrototypePattern(原型模式)----创建模式
  13. delphi with... do和自定义变量重名
  14. linux的越墙方法
  15. 标准SQL资料整理
  16. 【转】每天一个linux命令(31): /etc/group文件详解
  17. Windows安装TensorFlow遇到错误
  18. Security1:登录和用户
  19. OpenCV-Python(1)在Python中使用OpenCV进行人脸检测
  20. C语言:1孩半问题

热门文章

  1. 微信小程序-tab标签栏实现教程
  2. 一站式机器学习平台TI-ONE是什么?——云+未来峰会开发者专场回顾
  3. HTTP协议(二)header标头说明
  4. ExtJs6自定义scss解决actionColum中iconCls图标不能调样式的问题
  5. NOI 2018 酱油记
  6. SSRS Report Knowledge Base
  7. &lt;td&gt;标签clospan和rowspan 可横跨列数和行数
  8. JAVA线程池的原理分析
  9. 初步理解impress.js
  10. log4j的简单使用