控制器设置:

abstract class ControllerBase extends Controller
{
public function __construct($id, $module, $config = [])
{
parent::__construct($id, $module, $config);
} public function beforeAction($action)
{
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header('Access-Control-Allow-Credentials: true');
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");
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
\Yii::$app->response->setStatusCode(204);
\Yii::$app->end(0);
}
return parent::beforeAction($action);
}
}

nginx设置:

server {
listen 80;
server_name xxx-dev.myfuwu.cn;
root /webser/www/xxx/web;
index index.php;
access_log "pipe:/usr/local/sbin/sbin/cronolog /webser/logs/tengine/cronolog/%Y/%m/%Y-%m-%d_access_xxx.log" wwwlogs;
error_log "pipe:/usr/local/sbin/sbin/cronolog /webser/logs/tengine/cronolog/%Y/%m/%Y-%m-%d_error_xxx.log" warn; location ~ /static {
try_files $uri $uri/ /static/index.html =404;
} location / {
set $cors "true"; if ($request_method = 'OPTIONS') {
set $cors "${cors}options";
} add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
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'; # ifit's OPTIONS, then it's a CORS preflight request so respond immediately with no response body
if ($cors = "trueoptions") {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain charset=UTF-8';
return 204;
} try_files $uri $uri/ /index.php;
include /webser/www/xxx/web/nginx-rewrite.conf;
} location ~ \.php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9001;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
# fastcgi_param SCRIPT_NAME $real_script_name;
# fastcgi_param PATH_INFO $path_info;
# fastcgi_param TAG $real_script_name;
} location ~* ^.+\.(jpg|jpeg|gif|png|bmp|css|js|swf)$ {
access_log off;
#break;
} location =/check.html
{
root /webser/www;
access_log off;
} }

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. os4开始CLLocationManager类中不支持locationServicesEnabled属性了

    locationServicesEnabled改为类方法 //判断定位服务是否开启 if ([CLLocationManager locationServicesEnabled]) { }

  2. MVC - 模型验证

    使用MVC的数据验证特性可以自动实现客户端验证和服务端验证 假设有一个Employee类 public class Employee { public int ID { get; set; } pub ...

  3. [整理]:oracle spool 用法

    本文来自iDB Stock:http://www.idb-stock.net/idb/2011/06/01/153.html 1.spool的作用是什么? spool的作用可以用一句话来描述:在sql ...

  4. Modelsim覆盖率

    步骤: 1.compile选项 => compile options  Covrage setting  (或者可以点击选中文件,编辑properties,在coverage中选择要实现的覆盖选 ...

  5. Click ListView Item跳转Activity

    今天学习了ListView点击Item跳转,修改上一篇代码bindData方法 lv.setOnItemClickListener(new OnItemClickListener() { public ...

  6. SQLSERVER一些公用DLL的作用解释

    如果你的SQLSERVER安装在C盘的话,下面的路径就是相应SQLSERVER版本的公用DLL的存放路径 SQL2005 C:\Program Files\Microsoft SQL Server\9 ...

  7. Use excel Macro export data from database

    Sub DownLoadMacro() '定义过程名称 Dim i As Integer, j As Integer, sht As Worksheet 'i,j为整数变量:sht 为excel工作表 ...

  8. xCode如何导入自定义的snippets文件

    xCode代码块snippets导入 目标文件放置位置 ~/Library/Developer/Xcode/UserData/CodeSnippets 操作方法: 解压缩并复制到以下目录即可

  9. JS实现回到页面顶部动画效果 2016.03.23

    最近在模仿各大网站写页面样式和交互,发现好多都有回到顶部的需要,所以写了一下js,记录下来. 发现还可以添加从快到慢的动画效果和随时下拉滚动条停止滚动的功能, 参考了imooc上相关课程,最终实现JS ...

  10. 时间处理得到UTC时间

    在工作过程遇到了时间处理的问题,因为需要统一将时间处理按照utc时间进行处理,因此,不能简单的通过系统运行直接得到时间的毫秒数,这样会在不同时区得到的值是不同的. import java.text.P ...