【问题标题】:apache cross domain configurationapache跨域配置
【发布时间】:2015-08-05 10:04:24
【问题描述】:

我正在尝试在我的服务器上设置此应用程序openspeedtest.com self-hosted app 他们提供了 Nginx 配置。如何在我的 apache 共享托管服务器上完成这项工作?

fastcgi_read_timeout 360;
client_max_body_size 2000M;
location / {
    if ($http_origin) {
        add_header 'Access-Control-Allow-Origin' 'http://openspeedtest.com';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

          }
if ($request_method = OPTIONS ) {
        add_header Access-Control-Allow-Credentials "true";
        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
        add_header Access-Control-Allow-Origin "http://openspeedtest.com";        
        add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
        return 204;
            }
        }

【问题讨论】:

    标签: php apache nginx


    【解决方案1】:

    将此添加到您的服务器!

    在 Apache 上设置 CORS(跨域资源共享)。使用此配置创建 .htacess 文件。

    # Always set these headers.
    Header always set Access-Control-Allow-Origin "http://openspeedtest.com"
    Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
    
    # Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule ^(.*)$ $1 [R=200,L]
    #Don't forget to activate the apache module headers a2enmod headers
    

    【讨论】:

    • 谢谢!为此,救了我的命
    猜你喜欢
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 2011-12-10
    • 2017-10-01
    • 1970-01-01
    • 2013-08-17
    • 2019-11-11
    相关资源
    最近更新 更多