avatar

sunday

Sunday's Blog

  • 首页
Home nginx设置多个允许跨域的请求源
文章

nginx设置多个允许跨域的请求源

Posted 2024-10-30 Updated 2024-10- 30
By sunday 已删除用户
1~1 min read
# 定义允许的源列表
map $http_origin $cors_origin {
    "https://youdomian.com" "https://youdomian.com";
    "http://localhost:3010" "http://localhost:3010";
}

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        # 检查是否匹配允许的 Origin,如果匹配则设置 CORS 头
        if ($cors_origin) {
            add_header 'Access-Control-Allow-Origin' $cors_origin;
            add_header 'Access-Control-Allow-Credentials' 'true';        
        }

        # 其他配置...
    }
}

nginx
nginx
License:  CC BY 4.0
Share

Further Reading

Aug 23, 2025

nginx + acme 不占用80端口申请证书

1.在你的域名conf里配置如下 server { listen 80; listen [::]:80; server_name your_domain.com; # ← 改为你的域名或IP location ^~ /.well-known/acme-challen

Oct 30, 2024

nginx设置多个允许跨域的请求源

# 定义允许的源列表 map $http_origin $cors_origin { "https://youdomian.com" "https://youdomian.com"; "http://localhost:3010" "http://localhost:3010"; }

Apr 2, 2024

已安装的nginx,动态模块开启google brotli 压缩,并在vite项目中启用

1.下载ngx_brotli 到github https://github.com/google/ngx_brotli 然后git clone cd /usr/local/ git clone https://github.com/google/ngx_brotli.git cd /usr/loca

OLDER

python创建独立虚拟运行环境

NEWER

github actions 自动部署 standalone模式的nextjs

Recently Updated

  • nginx + acme 不占用80端口申请证书
  • 免费CDN 阿里云ESA 加速国内网站
  • nextjs15使用ai sdk的一些问题
  • 导致DNS泄露的一些问题
  • 为MCP服务添加简单验证,并部署到服务器上

Trending Tags

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy