Skip to main content

Scope of the Lightweight Proxy

The lightweight proxy solution (route_path-based forwarding) is primarily designed for backend API and HTTP request forwarding. It does not guarantee full compatibility with complex Web UI applications, such as ComfyUI, Gradio, or other SPA-based interfaces. These applications typically rely on static asset routing, frontend path resolution, and WebSocket connections, which may not function correctly under simple path-based forwarding. If you need to expose a complete Web UI application, we recommend deploying a standard reverse proxy (e.g., Nginx) inside the container to handle routing and asset forwarding properly.

Route-Based Forwarding with proxy_in_instance

Assuming you have two services running inside your container, listening on ports 2000 and 3000 respectively, here is an example using Flask:
python
# Simulate a service listening on port 2000
from flask import Flask
app = Flask(__name__)

@app.route('/v1/hello')
def hello():
    return 'I`m port 2000'

if __name__ == '__main__':
    app.run(port=2000)


# Simulate a service listening on port 3000
from flask import Flask
app = Flask(__name__)

@app.route('/v2/hello')
def hello():
    return 'I`m port 3000'

if __name__ == '__main__':
    app.run(port=3000)
Below, we will start a routing and forwarding service on port 6006. If the route matches /v1/*, it will forward the request to the service listening on port 2000. If the route matches /v2/*, it will forward the request to the service listening on port 3000. D ownload the proxy service program: First, download the proxy service program using the following command:
wget https://autodl-public.ks3-cn-beijing.ksyuncs.com/tool/api-proxy/proxy_in_instance
Create the config.yaml file: In the same directory as the downloaded proxy service program, create a file named config.yaml with the following content:
yaml
proxies:
  - host_and_port: http://127.0.0.1:2000  # Address of the service to proxy
    route_path: /v1/*                    # Route path to forward to this address

  - host_and_port: http://127.0.0.1:3000  # Multiple entries can be set to forward to different hosts
    route_path: /v2/*
Start the proxy service:
bash
# If the proxy program is not downloaded, download it using the command above.
wget https://autodl-public.ks3-cn-beijing.ksyuncs.com/tool/api-proxy/proxy_in_instance
yaml
# If the proxy program does not have executable permissions, add the permissions
chmod +x proxy_in_instance
bash
# Start the proxy service:
./proxy_in_instance