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

相关推荐
木二_17 小时前
附058.Kubernetes Gitea部署
ci/cd·kubernetes·gitea
慧一居士2 天前
Gitea和GitLab对比
运维·gitlab·gitea
ZeroNews内网穿透7 天前
轻量级自托管Git服务:Gitea私有化部署与公网访问
服务器·网络·数据库·git·gitea
空气中的告白13 天前
gitea安装及使用方法(常用命令)
gitea
bigHead-19 天前
Gitea的安装与简单使用
gitea
weixin_4643076324 天前
windows使用gitea迁移仓库
gitea
不爱吃米饭_1 个月前
Gitea 轻量级的Git方案 - Gitlab的替代品
git·gitlab·gitea
熊明才1 个月前
Gitea Actions步骤全解析:从入门到精通
gitea
自己的九又四分之三站台1 个月前
GitLab vs Gitea 全面对比:企业级 DevOps 还是轻量级私有仓库?
ci/cd·gitlab·devops·gitea
沟通QQ:4877392781 个月前
ACC巡航控制分层控制:上层PID与下层PID的奇妙组合
gitea