zoukankan      html  css  js  c++  java
  • FastAdmin 关于跨域问题解决

    FastAdmin 关于跨域问题解决

    之前很久之前收集到社区的问题。
    https://forum.fastadmin.net/thread/277

    今天又有人问到,无法打开,估计是网络问题。

    以下为完整配置 [1]

    #
    # CORS header support
    #
    # One way to use this is by placing it into a file called "cors_support"
    # under your Nginx configuration directory and placing the following
    # statement inside your **location** block(s):
    #
    #   include cors_support;
    #
    # As of Nginx 1.7.5, add_header supports an "always" parameter which
    # allows CORS to work if the backend returns 4xx or 5xx status code.
    #
    # For more information on CORS, please see: http://enable-cors.org/
    # Forked from this Gist: https://gist.github.com/michiel/1064640
    #
    
    set $cors '';
    if ($http_origin ~ '^https?://(localhost|www.yourdomain.com|www.yourotherdomain.com)') {
            set $cors 'true';
    }
    
    if ($cors = 'true') {
            add_header 'Access-Control-Allow-Origin' "$http_origin" always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
            # required to be able to read Authorization header in frontend
            #add_header 'Access-Control-Expose-Headers' 'Authorization' always;
    }
    
    if ($request_method = 'OPTIONS') {
            # Tell client that this pre-flight info is valid for 20 days
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
    }
    

    1. https://gist.github.com/Stanback/7145487 ↩︎

  • 相关阅读:
    ACwing 199 约数之和
    Acwing 222 青蛙的约会
    Acwing 220 最大公约数
    Acwing 200 Hankson的趣味题
    牛客 同余方程
    Acwing 198 反素数
    2020牛客多校 第六场B
    牛客 计数器
    Java基础-快捷键以及DOS命令
    A1111 Online Map (30分)(最短路径、Dijkstra+DFS)
  • 原文地址:https://www.cnblogs.com/F4NNIU/p/fastadmin-nginx-20180405.html
Copyright © 2011-2022 走看看