Nginx 配置跨域权限

今天设置静态资源服务器时发现

Font from origin ‘http://start.fbzl.org‘ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘http://lib.fbzl.org‘ is therefore not allowed access.

这里我给静态资源单独设置了一个域名,其它页面调用时发生了跨越权限问题。

Nginx 解决办法:

1 add_header Access-Control-Allow-Origin *;
2
3 add_header Access-Control-Allow-Headers X-Requested-With;
4
5 add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

将这段代码添加到 http{} 或者静态资源对应的 server{}

如果只为自己的网站使用可以将第一行代码的星号改为自己的域名,例如 *.fbzl.org

时间: 2024-08-05 22:11:06

Nginx 配置跨域权限的相关文章

nginx配置跨域、gzip加速、代理详细讲解

1.配置跨域 这个很简单,直接打开配置nginx.conf ,在http下配置下面三行代码:当然如果你是想某一个虚拟主机下跨域,那就在哪个server下面添加 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; 2.配置gzip,压缩访

Nginx配置跨域请求 Access-Control-Allow-Origin *

当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服务器配置响应的header参数: 一. 解决方案 只需要在Nginx的配置文件中配置以下参数: location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, P

nginx配置跨域访问

前端要在本地测试ajax接口,无法跨域访问,所以在测试环境的nginx配置了跨域支持,方法如下: 在nginx.conf文件, http块下配置 42 #support cross domain access 43 add_header Access-Control-Allow-Origin *; 44 add_header Access-Control-Allow-Headers X-Requested-With; 45 add_header Access-Control-Allow-Meth

nginx配置跨域

location / { if ($request_method = 'OPTIONS') {add_header 'Access-Control-Allow-Origin' '*' always;add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;## Custom headers and headers various browsers *should* be OK with but aren't#add

让Apache 和nginx支持跨域訪问

1,怎样让Apache支持跨域訪问呢? 步骤: 改动httpd.conf,windows中相应的文件夹是:C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf 把LoadModule headers_module modules/mod_headers.so 前面的凝视删除 改动 改为: 即: <Directory /> AllowOverride none Require all granted Header set Access-Control-Al

System.Web.Http.Cors配置跨域访问的两种方式

System.Web.Http.Cors配置跨域访问的两种方式 使用System.Web.Http.Cors配置跨域访问,众多大神已经发布了很多文章,我就不在详细描述了,作为小白我只说一下自己的使用心得.在webapi中使用System.Web.Http.Cors配置跨域信息可以有两种方式.  一种是在App_Start.WebApiConfig.cs的Register中配置如下代码,这种方式将在所有的webapi Controller里面起作用. using System; using Sys

让Apache 和nginx支持跨域访问

1,如何让Apache支持跨域访问呢? 步骤: 修改httpd.conf,windows中对应的目录是:C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf 把LoadModule headers_module modules/mod_headers.so 前面的注释删除 修改 改为: 即: <Directory /> AllowOverride none Require all granted Header set Access-Control-All

Apache 和nginx支持跨域访问

1,如何让Apache支持跨域访问呢? 步骤: 修改httpd.conf,windows中对应的目录是:C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf 把LoadModule headers_module modules/mod_headers.so 前面的注释删除 修改  改为:  即: <Directory />    AllowOverride none    Require all granted    Header set Access-

win2003 配置跨域邮件服务器

win2003 配置跨域邮件服务器