当前位置: 首页 > news >正文

nginx 配置允许跨域

当前端页面和后端应用的协议、IP、端口有任意一项不一样时,就会出现跨域问题,对于这种情况我们可以在后端应用前加一个nginx ,在server{location/{ …}}中配置可以跨域

完整配置文件如下:

worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       8090;server_name  localhost;location / {add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Credentials' 'true';proxy_pass http://10.18.35.246:30001;if ($request_method = OPTIONS){add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Max-Age' 1728000;add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE';add_header 'Access-Control-Allow-Headers' 'reqid, nid, host, x-real-ip, x-forwarded-ip, event-type, event-id, accept, content-type';proxy_pass http://10.18.35.246:30001;return 200;}}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}server {listen       8091;server_name  localhost;location / {add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Credentials' 'true';proxy_pass http://10.18.35.246:31001;if ($request_method = OPTIONS){add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Max-Age' 1728000;add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE';add_header 'Access-Control-Allow-Headers' 'reqid, nid, host, x-real-ip, x-forwarded-ip, event-type, event-id, accept, content-type';proxy_pass http://10.18.35.246:31001;return 200;}}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}}


http://www.mrgr.cn/news/3737.html

相关文章:

  • wps题注为表格或图片编号
  • 自定义xxx-spring-boot-starter
  • 低安卓版本页面空白适配
  • Spring Boot 实战:集成 Apache Kafka 及注意事项
  • 【22-54】创建者模式(详解五大模式)
  • gligen 训练自己的数据
  • I2C学习:上拉电阻选取
  • 密码学之哈希算法
  • 總結熱力學_3
  • Vscode——如何实现 Ctrl+鼠标左键 跳转函数内部的方法
  • UX已死,产品重生
  • freecad遭遇网络不同无法安装插件Addon Manager: Unexpected 0 response from server
  • OpenJDK 和 OracleJDK 的区别、下载方式
  • playbook(剧本)基本应用、playbook常见语法、playbook和ansible操作的编排
  • AWS CDK测试初探:掌握Assertion测试模式
  • 【异步IO】libeventlibevlibuv的相关认识
  • 【uniapp】图片合成并导入base64
  • 基于RDMA技术的Mayastor解决方案
  • Ajax技术详解
  • python 将mysql转为csv、json导入到Doris数据库