在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/人工智能  Linux/ 前端跨域訪問了,nginx怎么配置

前端跨域訪問了,nginx怎么配置

nginx配置跨域訪問后 get,post可以訪問,但是put方法不行

具體配置如下

add_header Access-Control-Allow-Origin *;

location / {
   if ($request_method = 'OPTIONS') {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
    return 204;
}

然后報錯提示了

index.html:1 Failed to load http://ms.iot-sw.net:7880/service/v1/shareport/park/4: Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.

有哪位大神知道怎么配置可以支持put方法嗎

回答
編輯回答
葬愛

這種配置只處理了 OPTIONS 請求。OPTIONS 請求不轉(zhuǎn)給后端,直接返回 204,并允許跨域。

對于其它請求,需要在前面再加一段:

location / {
   add_header Access-Control-Allow-Origin *;
   add_header Access-Control-Allow-Headers X-Requested-With;
   add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
    
   if ($request_method = 'OPTIONS') {
     return 204;
   }
}
2017年7月3日 20:48