Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

关于反代的问题 #407

@wang666233-art

Description

@wang666233-art

请问反代该怎么配置,我想把这个api用到pixiv-viewer上,用caddy进行反代,如果只是这样配置的话

xxx.com {
    tls [email protected]
    reverse_proxy 127.0.0.1:8089
}

会连接失败,似乎是需要配置跨域。网上查了一下后将配置修改为

xxx.com{
    tls [email protected]
    reverse_proxy 127.0.0.1:8089 {
        header_up Host {upstream_hostport}
    }

# 指定一个匹配 OPTIONS 请求方法的匹配器
@cors_preflight {
    method OPTIONS
    header Origin *
    }

# 处理这个匹配器,返回 204,并且允许跨域
    handle @cors_preflight {
        respond 204
        header Access-Control-Allow-Origin "*"
        header Access-Control-Allow-Methods "GET, POST, OPTIONS"
        header Access-Control-Allow-Headers "*"
    }

# 设置允许跨域的响应头
    header {
        Access-Control-Allow-Origin *
        Access-Control-Allow-Methods "GET, POST, OPTIONS"
    }
}

但这样配置后也有一些问题,比如小说加载不出正文,推荐和发现模块不显示。api地址换成您的api.obfs.dev则没有这些问题,请问您是怎么配置反代的?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions