zoukankan      html  css  js  c++  java
  • 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;
        }
    
    }
  • 相关阅读:
    P2P技术简介(包括BT软件的分析)(转)
    为什么BT网络中迅雷的速度会这么快,比其它BT软件快
    迅雷中几个概念
    BT中的磁力链接(转)
    eclipse代码不能自动提示的问题解决
    eclipse不会自动编译的问题解决
    BT网络中DHT和UPnp的解释(转)
    BT服务器的搭建(tracker-P2P服务器架设)(转)
    BT原理分析(转)
    BT种子文件文件结构分析(转)
  • 原文地址:https://www.cnblogs.com/stones/p/5435529.html
Copyright © 2011-2022 走看看