---
title: "nginx配置跨域请求"
author: "vinnie424"
date: "2020-12-28T15:40:49Z"
tags: []
categories: ["移动开发"]
slug: "nginx"
draft: false
lastmod: "2020-12-28T15:40:49Z"
id: 2518292
url: "https://vinnie424.iteye.com/blog/2518292"
---

location / {  
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

    if ($request_method = 'OPTIONS') {
        return 204;
    }
}

源自：
https://segmentfault.com/a/1190000012550346
https://www.cnblogs.com/yibinboy/p/12872890.html