控制器设置:

  1. abstract class ControllerBase extends Controller
  2. {
  3. public function __construct($id, $module, $config = [])
  4. {
  5. parent::__construct($id, $module, $config);
  6. }
  7.  
  8. public function beforeAction($action)
  9. {
  10. header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  11. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  12. header('Access-Control-Allow-Credentials: true');
  13. header("Access-Control-Allow-Headers: Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since");
  14. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  15. \Yii::$app->response->setStatusCode(204);
  16. \Yii::$app->end(0);
  17. }
  18. return parent::beforeAction($action);
  19. }
  20. }

nginx设置:

  1. server {
  2. listen 80;
  3. server_name xxx-dev.myfuwu.cn;
  4. root /webser/www/xxx/web;
  5. index index.php;
  6. access_log "pipe:/usr/local/sbin/sbin/cronolog /webser/logs/tengine/cronolog/%Y/%m/%Y-%m-%d_access_xxx.log" wwwlogs;
  7. error_log "pipe:/usr/local/sbin/sbin/cronolog /webser/logs/tengine/cronolog/%Y/%m/%Y-%m-%d_error_xxx.log" warn;
  8.  
  9. location ~ /static {
  10. try_files $uri $uri/ /static/index.html =404;
  11. }
  12.  
  13. location / {
  14. set $cors "true";
  15.  
  16. if ($request_method = 'OPTIONS') {
  17. set $cors "${cors}options";
  18. }
  19.  
  20. add_header 'Access-Control-Allow-Origin' "$http_origin";
  21. add_header 'Access-Control-Allow-Credentials' 'true';
  22. add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  23. add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
  24.  
  25. # ifit's OPTIONS, then it's a CORS preflight request so respond immediately with no response body
  26. if ($cors = "trueoptions") {
  27. add_header 'Access-Control-Max-Age' 1728000;
  28. add_header 'Content-Length' 0;
  29. add_header 'Content-Type' 'text/plain charset=UTF-8';
  30. return 204;
  31. }
  32.  
  33. try_files $uri $uri/ /index.php;
  34. include /webser/www/xxx/web/nginx-rewrite.conf;
  35. }
  36.  
  37. location ~ \.php {
  38. include fastcgi_params;
  39. fastcgi_pass 127.0.0.1:9001;
  40. fastcgi_split_path_info ^(.+\.php)(.*)$;
  41. fastcgi_param PATH_INFO $fastcgi_path_info;
  42. fastcgi_index index.php;
  43. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  44.  
  45. #fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  46. # fastcgi_param SCRIPT_NAME $real_script_name;
  47. # fastcgi_param PATH_INFO $path_info;
  48. # fastcgi_param TAG $real_script_name;
  49. }
  50.  
  51. location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf)$ {
  52. access_log off;
  53. #break;
  54. }
  55.  
  56. location =/check.html
  57. {
  58. root /webser/www;
  59. access_log off;
  60. }
  61.  
  62. }

Yii 跨域设置的更多相关文章

  1. chrome浏览器的跨域设置——包括版本49前后两种设置

    做前后分离的webapp开发的时候,出于一些原因往往需要将浏览器设置成支持跨域的模式,好在chrome浏览器就是支持可跨域的设置,网上也有很多chrome跨域设置教程.但是新版本的chrome浏览器提 ...

  2. vue-cli的跨域设置

    概述 今天打算快速使用vue-cli建立一个小应用用于测试,使用axios发送http请求,但是遇到了跨域问题,总结了一下,供以后开发时参考,相信对其他人也有用. vue-cli的跨域设置 在vue. ...

  3. WebApi服务以及跨域设置

    WCF 它利用TCP.HTTP.MSMQ等传输协议构建“契约先行”的服务.WCF最初为基于SOAP的服务而设计[xml],繁琐.冗余.慢.沉重 WebApi 基于http协议,轻量级的,支持URL路由 ...

  4. Mac下的Chrome或Safari访问跨域设置,MBP上使用模拟器Simulator.app或iphone+Safari调试网页

    Mac下的Chrome或Safari访问跨域设置: mac下终端启动Chrome $ open -a Google\ Chrome --args --disable-web-security 或 /A ...

  5. Asp.net core 跨域设置

    验证环境: dotnet core 2.1/Asp.net core2.1 一.作用域在中间件层  配置的方式是在startup.cs文件Configure(IApplicationBuilder a ...

  6. chrome浏览器的跨域设置 Google Chrome浏览器下开启禁用缓存和js跨域限制--disable-web-security

    chrome用户默认路径 Win7:C:\Users\[用户名]\AppData\Local\Google\Chrome\User Data\XP:C:\Documents and Settings\ ...

  7. jexus手动跨域设置

    AP.NET MVC默认跨域方法如下: <system.webServer> <validation validateIntegratedModeConfiguration=&quo ...

  8. SSO单点登录、跨域重定向、跨域设置Cookie、京东单点登录实例分析

    最近在研究SSO单点登录技术,其中有一种就是通过js的跨域设置cookie来达到单点登录目的的,下面就已京东商城为例来解释下跨域设置cookie的过程 涉及的关键知识点: 1.jquery ajax跨 ...

  9. Chrome Ajax 跨域设置

    一.前言 web 开发中 Ajax 是十分常见的技术,但是在前后端使用接口对接的调试过程中不可避免会碰到跨域问题.今天我给大家介绍一个十分简单有效的方法. 跨域经典错误 二.Chrome 跨域设置 首 ...

随机推荐

  1. ThinkPHP3.1快速入门(2)数据CURD

    上一篇中,我们了解了ThinkPHP的基础部分,以及如何创建一个控制器和模板,并知道了M方法的用法,本篇将会讲解下数据的CURD操作,探索下更多的数据操作. CURD CURD是一个数据库技术中的缩写 ...

  2. POJ 2488-A Knight&#39;s Journey(DFS)

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31702   Accepted: 10 ...

  3. UBUNTU 关闭iptables的方法

    UBUNTU没有相关的直接命令 请用如下命令 iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT tables是内核模块删除不了滴现查看一下你ipta ...

  4. KafkaSpout 浅析

    最近在使用storm做一个实时计算的项目,Spout需要从 KAFKA 集群中读取数据,为了提高开发效率,直接使用了Storm提供的KAFKA插件.今天抽空看了一下KafkaSpout的源码,记录下心 ...

  5. Java基础知识强化之IO流笔记43:IO流练习之 复制文本文件的 5 种方式案例

     1. 案例分析: 分析: 复制数据,如果我们知道用记事本打开并能够读懂,就用字符流,否则用字节流. 通过该原理,我们知道我们应该采用字符流更方便一些. 而字符流有5种方式,所以做这个题目我们有5种方 ...

  6. VB学习笔记

    stack segment stack 'stack' dw dup() ;此处输入堆栈段代码 stack ends data segment ;IBUF OBUF 看成是内存的地址,IBUF+1和I ...

  7. java与.net平台之间进行RSA加密验证

    RSA加密算法虽然不分平台,标准都是一样的,但是各个平台的实现方式都不尽相同,下面来我来说说java与.net平台之间该如何进行RSA加密验证,即java端加密->.net端验证和.net端加密 ...

  8. String类概述

    (1)多个字符组成的一串数据.        其实它可以和字符数组进行相互转换.    (2)构造方法:        A:public String()        B:public String ...

  9. 面向服务的体系结构(service-oriented architecture,SOA)

    SOA的概念是Gartner 在1996年提出来的,并于2002年12月进一步提出SOA是“现代应用开发领域最重要的课题”.   一.SOA的定义 SOA分为广义的SOA和狭义的SOA,广义的SOA是 ...

  10. (一)问候Hibernate4

    第一节:Hibernate 简介 官网:http://hibernate.org/ Hibernate 是一个开放源代码的对象关系映射框架,它对JDBC 进行了非常轻量级的对象封装,使得Java程序员 ...