1

我想在 nginx 单元级别处理 cors,但我不知道它是如何在 nginx 单元上生成的。nginx 的示例配置

if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS, DELETE, PATCH';
            add_header 'Access-Control-Allow-Headers' 'Authorization,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range';
            add_header 'Access-Control-Expose-Headers' 'Gc-Export-Errors';
            return 204;
        }

我如何为 nginx 单元执行此操作?

4

1 回答 1

0

目前,Nginx Unit 不支持等于的功能,add_header因此如果您需要自定义标头进行204响应,则应使用 application.properties 来完成。配置将如下所示:


{
   "match":{
      "method": "OPTIONS"
   },
   "action":{
      "proxy": "path/to/app_return_204_with_custom_headers"
   }
}

于 2021-11-28T14:04:11.423 回答