Yii 跨域设置
控制器设置:
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 跨域设置的更多相关文章
- chrome浏览器的跨域设置——包括版本49前后两种设置
做前后分离的webapp开发的时候,出于一些原因往往需要将浏览器设置成支持跨域的模式,好在chrome浏览器就是支持可跨域的设置,网上也有很多chrome跨域设置教程.但是新版本的chrome浏览器提 ...
- vue-cli的跨域设置
概述 今天打算快速使用vue-cli建立一个小应用用于测试,使用axios发送http请求,但是遇到了跨域问题,总结了一下,供以后开发时参考,相信对其他人也有用. vue-cli的跨域设置 在vue. ...
- WebApi服务以及跨域设置
WCF 它利用TCP.HTTP.MSMQ等传输协议构建“契约先行”的服务.WCF最初为基于SOAP的服务而设计[xml],繁琐.冗余.慢.沉重 WebApi 基于http协议,轻量级的,支持URL路由 ...
- Mac下的Chrome或Safari访问跨域设置,MBP上使用模拟器Simulator.app或iphone+Safari调试网页
Mac下的Chrome或Safari访问跨域设置: mac下终端启动Chrome $ open -a Google\ Chrome --args --disable-web-security 或 /A ...
- Asp.net core 跨域设置
验证环境: dotnet core 2.1/Asp.net core2.1 一.作用域在中间件层 配置的方式是在startup.cs文件Configure(IApplicationBuilder a ...
- chrome浏览器的跨域设置 Google Chrome浏览器下开启禁用缓存和js跨域限制--disable-web-security
chrome用户默认路径 Win7:C:\Users\[用户名]\AppData\Local\Google\Chrome\User Data\XP:C:\Documents and Settings\ ...
- jexus手动跨域设置
AP.NET MVC默认跨域方法如下: <system.webServer> <validation validateIntegratedModeConfiguration=&quo ...
- SSO单点登录、跨域重定向、跨域设置Cookie、京东单点登录实例分析
最近在研究SSO单点登录技术,其中有一种就是通过js的跨域设置cookie来达到单点登录目的的,下面就已京东商城为例来解释下跨域设置cookie的过程 涉及的关键知识点: 1.jquery ajax跨 ...
- Chrome Ajax 跨域设置
一.前言 web 开发中 Ajax 是十分常见的技术,但是在前后端使用接口对接的调试过程中不可避免会碰到跨域问题.今天我给大家介绍一个十分简单有效的方法. 跨域经典错误 二.Chrome 跨域设置 首 ...
随机推荐
- MySQL check the manual that corresponds to your MySQL server version for the right syntax错误
地化GO的时候一直遇到一个错误就是check the manual that corresponds to your MySQL server version for the right syntax ...
- 【05】了解C++默默编写并调用那些函数
1.如果没有声明copy构造方法,copy赋值操作符,和析构方法,编译器会自动生成这些方法,且是inline. 2.如果没有声明任何构造方法,编译器会自动生成一个default构造方法,且是inlin ...
- Ubuntu Server 12.04 静态IP简洁配置
PS:很长时间没使用Ubuntu了,刚才安装个Ubuntu Server 12.04做测试.Ubuntu的网络设置跟Redhat系是不一样的,配置IP时发现跟以前的Ubuntu桌面版本也有所不同,记录 ...
- iOS中的字符串扫描类NSScanner
新建一个Category,命名为UIColor+Hex,表示UIColor支持十六进制Hex颜色设置. UIColor+Hex.h文件, #import <UIKit/UIKit.h> # ...
- leetcode每日解题思路 221 Maximal Square
问题描述: 题目链接:221 Maximal Square 问题找解决的是给出一个M*N的矩阵, 只有'1', '0',两种元素: 需要你从中找出 由'1'组成的最大正方形.恩, 就是这样. 我们看到 ...
- MySQL【第一篇】安装
一.简介 MySQL 是最流行的关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言.MySQL由于其体积小. ...
- <转载>解决div里面img的缝隙问题
转载自:http://blog.sina.com.cn/s/blog_9fd5b6df01013mld.html 练习切图时发现img和父级div之间总是有2px空隙(chrome),上网搜索解决 ...
- c#面向对象编程基础
1. 为什么要有面向对象? (1) 增加代码重用. (2)降低维护负担,将具备独特性质的代码封装起来,修改程序时,相互不会影响. 2.数据封装用来解决全局变量不易维护的问题. 3.多态: ...
- lucene 4.4 demo
ackage com.zxf.demo; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStr ...
- Ajax异步的回调函数执行了多遍
问题: 在做下拉滚动加载时(类似于qq空间下拉加载),数据向下滚动一次,就会加载一次,即append一下,跟踪js后,发现回调函数执行了多次,导致append将上次的append结果append上了, ...