控制器设置:

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. JAVA自动生成正则表达式工具类

    经过很久的努力,终于完成了JAVA自动生成正则表达式工具类.还记得之前需要正则,老是从网上找吗?找了想修改也不会修改.现在不用再为此烦恼了,使用此生成类轻松搞定所有正则表达式.赶快在同事面前炫一下吧. ...

  2. java带图片的邮件发送方法实现

    package sendEmail; import java.util.Properties; import javax.activation.DataHandler; import javax.ac ...

  3. gitservergitlab之搭建和使用

    gitserver比較有名的是gitosis和gitolite,这两个管理和使用起来略微有些复杂,没有web页面,而gitlab则是类似于github的一个工具,github无法免费建立私有仓库,而且 ...

  4. DirectoryEntry 活动目录的使用

    public class DirectoryHelper { public static string DomainName = System.Environment.UserDomainName; ...

  5. shell 两个rpm包做差分

      当前目录下两个rpm包做差分. *.rpm 两个目录,解压rpm包. export LANG=c 差分判断是脚本还是Binary Files 脚本添加命令行提示符,awk. [root@sj_x8 ...

  6. oracle学习----特殊的连接方式

    1.笛卡儿积 merge join cartesion SQL> select ename,dname from emp,dept; 已选择56行. 执行计划------------------ ...

  7. iOS tableview 静态表布局纪录

    今天使用了tableview静态表布局,纪录如下 1:使用tableview 静态表,必须是UITableViewController 2:Content 中选择 Static Cells 如下图 3 ...

  8. case when then 与 count联合使用

    我们都知道SQL中适用case when then来转化数据库中的信息 比如  select (case sex when 0 then '男' else '女' end) AS sex  from ...

  9. CentOS 6.3 安装ATI显卡驱动

    环境: centos 6.3  内核(GNU貌似大家都知道) 显卡:ATI Mobility Radeon HD 3470 安装显卡流程: 1.官网下载最新驱动 http://support.amd. ...

  10. Css3炫酷总结使用

    先从CSS3的选择器说起: E F:所有的子孙元素: E>F: E中的子元素: E+F:E元素之后的最近的选择器: E~F:E中所以后面兄弟元素(CSS3 不包括自己本身,前面也不包括) att ...