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

相关推荐
IT WorryFree12 天前
GitHub / Gitee / Gitea / GitLab 四平台完整对比(定位、优缺点、适用场景)
gitee·github·gitea
日取其半万世不竭19 天前
Gitea SSH 克隆失败?域名、端口和 ROOT_URL 配置检查
运维·ssh·gitea
sunarmy21 天前
Windows安装gitea服务器指导
gitea
STDD21 天前
Gitea Actions Runner 搭建指南:为 Gitea 添加 CI/CD 自动化执行器
ci/cd·自动化·gitea
鱼听禅1 个月前
CentOS使用Nginx配置代理Gitea后网址设置正确,确保URL不匹配的问题记录
nginx·centos·gitea
babytiger1 个月前
Gitea 重安装 + Snap 数据迁移完整流程总结
linux·elasticsearch·gitea
西柚小萌新1 个月前
【计算机常识】--使用 Gitea 在本地/内网搭建 Git 私有服务器
服务器·git·gitea
微小冷1 个月前
Gitea初步使用教程
gitea
韭菜钟2 个月前
Git 代理与内网 Gitea 共存方案(无需 no_proxy)
git·gitea
HakunamatataWang3 个月前
怎么把github的本地的repo上传给gitea
github·gitea