Home > Backend Development > PHP Tutorial > nginx中access-control-allow-origin 字体跨域配置方法

nginx中access-control-allow-origin 字体跨域配置方法

不言
Release: 2023-02-28 15:34:01
Original
3661 people have browsed it

今天在使用外部调用bootstrap图标字体的时候

报了如下错误:

Font from origin 'http://www.scutephp.com' 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://w.scutephp.com' is therefore not allowed access. 

在nginx.conf中配置

location ~* \.(eot|ttf|woff|woff2|svg)$ {
	add_header Access-Control-Allow-Origin *;
	add_header Access-Control-Allow-Headers X-Requested-With;
	add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}
Copy after login

这样就可以实现GET,POST,OPTIONS的跨域请求的支持
也可以 add_header Access-Control-Allow-Origin  --指定允许的url;

Cross-Origin Resource Sharing设置查看

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template