TypechoJoeTheme

至尊技术网

统计
登录
用户名
密码
/
注册
用户名
邮箱

悠悠楠杉

网站页面

Apache与NGINX下Access-Control-Allow-Origin * 设置

2019-12-26
/
2 评论
/
1,233 阅读
/
正在检测是否收录...
12/26

介绍

网站一般在需要共享资源给其他网站时(跨域传递数据),才会设置access-control-allow-origin HTTP头
设置Access-Control-Allow-Origin,可以解决多域名跨域问题
Access-Control-Allow-Origin * 等所有网站都可以跨域访问
Access-Control-Allow-Origin zzwws.cn 允许zzwws.cn跨域访问

Apache

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin: "*"
    Header set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS"
    Header set Access-Control-Allow-Headers: "Content-Type"
</IfModule>

添加到httpd.conf最下面

NGINX

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'PUT,POST,GET,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With';

location / {  
  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
  add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
} 

将代码添加到NGINX

HTML

<meta http-equiv="Access-Control-Allow-Origin" content="*" />

Java

response.setHeader("Access-Control-Allow-Origin", "*"); 

.net

Response.AddHeader("Access-Control-Allow-Origin", "*");
教程经验ApacheNginxControl-Allow-Origin
朗读
赞(0)
版权属于:

至尊技术网

本文链接:

https://www.zzwws.cn/archives/2445/(转载时请注明本文出处及文章链接)

评论 (2)
  1. p89wbx8c 作者
    Windows 7 · Google Chrome

    看看!

    2019-12-28 回复
    1. 逃不开的宿命 作者
      Windows 7 · QQ Browser
      @p89wbx8c

      ?

      2019-12-28 回复