Gitea允许无请求头跨域

Gitea允许无请求头跨域

想要 Gitea 支持无请求头跨域(Access-Control-Allow-Origin without a Credential),可以通过配置 Nginx 来实现。

以下是一个 Nginx 配置示例,用于允许跨域请求而不带有认证信息(例如 cookies 或 HTTP 认证):

复制代码
server {
    listen 80;
    server_name gitea.example.com;
 
    location / {
        proxy_pass http://localhost:3000; # 假设 Gitea 运行在 localhost:3000
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        add_header 'Access-Control-Allow-Credentials' 'true';
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }
    }
}

将上述配置放置到反向代理的配置节点下。

注意:服务器环境为 1panel下的 OpenResty。

相关推荐
astronautyi9 天前
Gitea Push Mirror 镜像同步卡住:磁盘写满导致 LevelDB 队列异常的排查与恢复
gitea
深海里的鱼(・ω<)★14 天前
SMB备份导致的 Gitea 分支推送成功但界面不可见故障复盘
大数据·elasticsearch·gitea
撞强15 天前
手搓标讯系统实战——win11/CherryStudio/Icompify/剑鱼标讯/Gitea
gitea·手搓·cherrystudio·标讯
大貔貅喝啤酒1 个月前
Gitea+Jenkins+Docker 搭建 Node 项目 CI/CD 自动部署完整教程
ci/cd·docker·jenkins·js·gitea
zoutao982 个月前
Gitea Actions 自定义 Runner 镜像与自动化部署实战
ci/cd·docker·gitea
大貔貅喝啤酒2 个月前
CentOS8 + Docker 部署Gitea
自动化测试·gitea·docker 部署gitea
大喵桑丶2 个月前
AlmaLinux 9 上基于 PostgreSQL + Nginx 部署高可用轻量级 Gitea 服务
nginx·postgresql·gitea
暮云星影3 个月前
git版本发布
git·gitee·github·gitea
暮云星影3 个月前
git仓库分支管理
git·gitee·github·gitea
康娜喵3 个月前
在Ubuntu26上使用Docker部署Gitea
docker·容器·gitea