Code Monkey home page Code Monkey logo

port-mapping's Introduction

端口映射

项目介绍

本项目主要用来代理http服务,提供端口映射服务,可以作为网关使用。 比如可以将很多域名解析到本服务器,然后由本服务器代理到其他任意服务器。 比如一台连接了公网的服务器,然后很多台内网服务器,那么可以使用公网服务器转发请求的到内网服务器。 本项目也可以代理公网ip,将需要代理的服务ip地址换成公网ip即可。 当然本项目也可以用作类似于nginx的负载均衡的功能,不过需要调整服务端和客户端以及配置文件。 原理就是给每一个被代理的服务器设置权重,当浏览器访问这个代理服务器的某个端口的时候,服务端根据权重给对应的客户端转发http请求。

项目安装

composer create-project xiaosongshu/port-mapping

项目结构

|--config
  |-config.php              # 配置文件
|--temp_client_for_win      # windows环境 channel客户端运行目录
  |-tpl.php                 # windows环境 channel客户端模板文件
|--vendor                   # 扩展文件
  |-...
|--windows_server           # windows环境 服务端运行目录
  |-...
-   channel.php             # windows环境channel服务端文件
-   client.php              # linux环境channel客户端文件
-   client_for_win.bat      # windows环境启动文件
-   client_for_win.php      # windows环境 channel客户端生成器
-   common.php              # 公共函数
-   composer.json           # 项目依赖配置文件
-   composer.lock           # 项目依赖配置文件版本锁定文件
-   server.php              # linux环境服务端启动文件
-   server_for_win.php      # windows环境服务端模板文件
-   start_win_server.php    # windows环境服务端启动模板文件

配置

见config/config.php 。

<?php

return [
    /** 代理ip 本服务器ip地址 */
    "server_ip" => "127.0.0.1",
    /** 代理端口 本服务器暴露的端口 nat_list为空生效 */
    "server_port" => 8001,
    /** 映射ip 被代理的服务器的ip地址  nat_list为空生效 */
    "local_ip" => "127.0.0.1",
    /** 映射端口 被代理的服务器的端口 nat_list为空生效*/
    "local_port" => 9501,
    /** channel 通道端口 */
    "channel_port" => 2206,
    /** 端口映射表 */
    "nat_list" => [
        [
            /** 访问端口 */
            "server_port" => 8000,
            /** 映射端口 */
            "local_port" => 9501,
            /** 映射IP */
            "local_ip" => "127.0.0.1",
        ],
        [
            /** 访问端口 */
            "server_port" => 8400,
            /** 映射端口 */
            "local_port" => 80,
            /** 映射IP */
            "local_ip" => "156.236.71.182",
        ],
    ]
];

启动

linux环境

启动服务端

php server.php start (-d)

启动客户端

php client.php start (-d)

windows环境

直接双击client_for_win.bat文件即可,

关闭服务

在窗口按ctrl+c 可以关闭服务。

联系作者

[email protected]

port-mapping's People

Contributors

2723659854 avatar

Stargazers

Cloudflying avatar hkui avatar heropoo avatar  avatar codingon avatar  avatar Ben avatar  avatar

Watchers

 avatar

Forkers

mongdch

port-mapping's Issues

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.