The front end is accessed across domains. How to configure nginx

after nginx is configured to access cross-domain access, get,post can be accessed, but the put method is not allowed

the specific configuration is as follows

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;
}

then reported the wrong prompt

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.

does any great god know how to configure and support the put method

Mar.02,2021

this configuration only handles OPTIONS requests. The OPTIONS request is not forwarded to the backend, but returns 204 directly, and cross-domain is allowed.

for other requests, you need to add another paragraph before:

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;
   }
}
Menu