---
title: 后端nginx跨域CORS配置
description: 开发过程中为了简便一般通过前端的代理方式临时解决CORS跨域问题，在部署到生产环境的时候再切换到服务端做CORS跨域配置，这篇文章介绍后端是nginx的时候如何
author: chaihongjun
category: backend
published: 2024-09-30
url: https://chaihongjun.me/backend/28.html
---

# 后端nginx跨域CORS配置

![后端nginx跨域CORS配置](https://chaihongjun.me/public/uploads/images/20240930/1727680253672907.png)

服务器上创建⼀个⽂件 cors.conf ,建议放置在⽬录 /usr/local/nginx/conf/pugin：
MDBLOCK0
然后在主机配置中引入这个文件：
MDBLOCK1
最后记得要检测一下修改后的nginx配置文件是否正确。

以上内容参考自： [https://enable-cors.org/server_nginx.html](https://enable-cors.org/server_nginx.html)

---

> 本文首发于 [chaihongjun.me | 柴宏俊 web 技术学习笔记](https://chaihongjun.me/backend/28.html)，采用 CC BY-NC-ND 4.0 协议，转载请保留出处与链接。
