Error[2]: preg_replace_callback(): Compilation failed: quantifier does not follow a repeatable item at offset 7, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 432
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 432, preg_replace_callback(/(?)(*)/ , object , <===><===><===>Nginx配置跨域请求Access-Control-Allow-Origin * 详解 <===><===>[+++]<===><===> <===>当出现403跨域错误的时候 [+++],需要给Nginx服务器配置响应的header参数:<===> <===><===>[+++]<===><===> <===> <===>只需要在Nginx的配置文件中配置以下参数:<===> [+++] <===>上面配置代码即可解决问题了,不想深入研究的,看到这里就可以啦=-=<===> <===> <===><===><===>二、 解释<===> <===><===><===> <===>[+++]<===> <===> <===>服务器默认是不被允许跨域的。给Nginx服务器配置`Access-Control-Allow-Origin *`后,表示服务器可以接受所有的请求源(Origin),即接受所有跨域的请求。<===> <===> <===>[+++]<===> <===> <===> <===>Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.<===> <===> <===>这个错误表示当前请求Content-Type的值不被支持。其实是我们发起了"application/json"的类型请求导致的。这里涉及到一个概念:预检请求(preflight request),请看下面"预检请求"的介绍。<===> <===>[+++]<===> <===> <===> <===>Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.<===> <===> <===>[+++]<===> <===> <===>发送"预检请求"时,需要用到方法 OPTIONS ,所以服务器需要允许该方法。<===> <===><===>[+++]<===><===> <===> <===>其实上面的配置涉及到了一个W3C标准:CROS,全称是跨域资源共享 (Cross-origin resource sharing),它的提出就是为了解决跨域请求的。<===> <===> <===>跨域资源共享(CORS)标准新增了一组 HTTP 首部字段,允许服务器声明哪些源站有权限访问哪些资源。另外,规范要求,对那些可能对服务器数据产生副作用的HTTP 请求方法(特别是 GET 以外的 HTTP 请求,或者搭配某些 MIME 类型的 POST 请求),浏览器必须首先使用 OPTIONS 方法发起一个预检请求(preflight request),从而获知服务端是否允许该跨域请求。服务器确认允许之后,才发起实际的 HTTP 请求。在预检请求的返回中,服务器端也可以通知客户端,是否需要携带身份凭证(包括 Cookies 和 HTTP 认证相关数据)。<===> <===> <===> <===>其实Content-Type字段的类型为application/json的请求就是上面所说的搭配某些 MIME 类型的 POST 请求,CORS规定,Content-Type不属于以下MIME类型的,都属于预检请求:<===> <===> <===>application/x-www-form-urlencoded<===> multipart/form-data<===> text/plain<===> <===> <===> <===>所以 application/json的请求 会在正式通信之前,增加一次"预检"请求,这次"预检"请求会带上头部信息 Access-Control-Request-Headers: Content-Type:<===> [+++] <===>服务器回应时,返回的头部信息如果不包含Access-Control-Allow-Headers: Content-Type则表示不接受非默认的的Content-Type。即出现以下错误:<===> <===> <===>Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.<===> <===> <===>参考文章:<===> <===> [+++] [+++] <===> <===><===>[+++]<===><===> <===>以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。<===> , 1)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[2]: preg_replace_callback(): Compilation failed: quantifier does not follow a repeatable item at offset 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 445
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 445, preg_replace_callback(/(?)(*)/ , object , , 1)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Nginx配置跨域请求Access-Control-Allow-Origin * 详解_软件运维_内存溢出

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/898400.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-15
下一篇 2022-05-15

发表评论

登录后才能评论

评论列表(0条)

保存