nginx里配置跨域
2024-08-27 23:19:32
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;
}
访问的是 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";
}
最新文章
- 【转载】 ionic 的 下拉刷新 与 上拉加载
- Maven 初学(一)基本概念
- [转]Web Service Authentication
- xxx_cast类型转换
- NVMe 图解
- 为Delphi程序增加UAC功能(每个步骤都很详细)
- KafkaOffsetMonitor
- MVC5+EF6 入门
- CSS 常用样式 提高网页编写速度
- hdu 2196 Computer(树形DP经典)
- robotframework2.8.7日志输出List乱码
- 设计模式のPrototypePattern(原型模式)----创建模式
- delphi with... do和自定义变量重名
- linux的越墙方法
- 标准SQL资料整理
- 【转】每天一个linux命令(31): /etc/group文件详解
- Windows安装TensorFlow遇到错误
- Security1:登录和用户
- OpenCV-Python(1)在Python中使用OpenCV进行人脸检测
- C语言:1孩半问题