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

相关推荐
Linux猿18 天前
828华为云征文 | 云服务器Flexus X实例:部署 Gitea,拥有自己的Git仓库,管理本地代码
服务器·华为云·gitea·云服务器·git仓库·flexus云服务器x实例·华为云服务器
野猪佩挤22 天前
Gitea Action注册runner
gitea
野猪佩挤23 天前
Gitea Action 简单配置(CI/CD)
ci/cd·gitea
Ryan爱吃糖1 个月前
Centos安装配置Gitea(Ubuntu等系统也可参考)
linux·centos·gitea
易秋之1 个月前
gitea + drone实现CI/CD
ci/cd·gitea
yuansec2 个月前
使用Gitea搭建git本地服务器
git·ubuntu·gitea
zhamors2 个月前
Linux(CentOS)环境搭建Gitea做私有的git服务器
git·gitea
程序员不想敲代码啊2 个月前
【全面介绍下Gitea,什么是Gitea?】
gitea
程序员不想YY啊3 个月前
【简单介绍Gitea】
gitea
007php0074 个月前
探索智慧农业系统架构的设计与应用
java·运维·经验分享·笔记·git·gpt·selenium·其他·百度·docker·微信·chatgpt·ai作画·架构·golang·系统架构·centos·gitlab·rabbitmq·github·aigc·测试用例·php·集成测试·负载均衡·压力测试·postman·文心一言·课程设计·ai编程·微信公众平台·测试覆盖率·facebook·composer·agi·安全性测试·paddle·新浪微博·segmentfault·gitea·微信开放平台