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

相关推荐
嘎嘎NULL7 天前
Gitea配置邮箱
运维·服务器·gitea
嘎嘎NULL7 天前
Gitea禁止注册和Gitea禁止未登录用户探索仓库
gitea
嘎嘎NULL7 天前
Gitea上传文件限制 Dropzone upload error: You can not upload any more files.
gitea
Hvitur11 天前
Gitea 版本控制服务端
gitea
猫头虎19 天前
Gitea 服务器搭建:如何在公司服务器搭建 Gitea 环境实现代码仓库私有化托管
运维·服务器·git·github·ai编程·gitea·gitcode
路由侠内网穿透.23 天前
本地部署代码托管解决方案 Gitea 并实现外部访问( Windows 版本)
运维·服务器·网络协议·gitea
吹牛不交税23 天前
gitea安装windows并实现CICD持续集成部署
ci/cd·gitea
不像程序员的程序媛1 个月前
gitea基本操作
gitea
阿里巴巴P8资深技术专家1 个月前
Docker一站式部署:RustFS、GoFastDFS、Gitea与PostgreSQL实战指南
docker·postgresql·gitea
木二_2 个月前
附058.Kubernetes Gitea部署
ci/cd·kubernetes·gitea