apache跨域配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache跨域配置相关的知识,希望对你有一定的参考价值。

我试图在我的服务器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;
            }
        }
答案

将其添加到您的服务器!

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

# 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

以上是关于apache跨域配置的主要内容,如果未能解决你的问题,请参考以下文章

apache跨域图片配置

apache跨域配置

配置linux下apache跨域问题

Apache 2.4 跨域

Apache Windows配置-----跨域CORS设置-----HTTP响应头设置-------dplayer调用apache服务时的header filed range报错解决

Apache Windows配置-----跨域CORS设置-----HTTP响应头设置-------dplayer调用apache服务时的header filed range报错解决