GithubHelp home page GithubHelp logo

dev-proxy's Introduction

dev-proxy

项目简介

dev-proxy 是一个基于 Go 语言开发的代理服务器项目,配合 pm2 和 nginx 使用,能够动态解析域名并进行反向代理。它允许你根据配置文件 hostmap.json 动态映射域名,提供灵活高效的代理解决方案。

环境要求

  • Go 1.22.4
  • pm2
  • nginx

配置文件

hostmap.json 样例

{
  "docker": "r.docker.com"
}

使用步骤

4.1 解析域名

确保你的域名解析配置正确,域名前缀需要与 hostmap.json 中的 key 对应。例如,在 hostmap.json 中有如下配置:

{
  "docker": "r.docker.com"
}

那么所有以 docker. 开头的域名都会被自动映射到 r.docker.com

4.2 编译

首先需要编译 dev-proxy 项目。进入项目根目录,执行以下命令:

make

这将使用 Makefile 编译项目源码并生成二进制文件。

4.3 启动服务

使用 pm2 启动编译后的服务。确保根目录下存在 pm2 的配置文件 ecosystem.config.cjs,然后执行以下命令:

pm2 start ecosystem.config.cjs

该命令会启动 dev-proxy 服务并进行管理。

4.4 配置反向代理

根据项目要求修改 nginx.conf 文件来配置反向代理。以下是一个示例配置:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:8080; # 假设 dev-proxy 在 8080 端口运行
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

example.com 替换为你的域名,并确保 proxy_pass 的地址与 dev-proxy 运行的地址和端口一致。

4.5 完成

至此,你已经顺利配置并运行 dev-proxy 项目,能够动态解析域名并进行灵活的反向代理。

贡献

如果你有任何改进建议或发现问题,欢迎提交 pull request 或 issue。

许可证

dev-proxy 项目基于 MIT 许可证进行开源。详细信息请查看LICENSE 文件。

dev-proxy's People

Watchers

echo rosen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.