1个不稳定版本

0.1.0 2023年1月28日

#1055HTTP服务器

自定义许可证

74KB
1K SLoC

RXH

RXH是一个用hypertokio构建的HTTP反向代理,仅出于娱乐目的。配置文件(rxh.toml)接受这些选项

# Simple proxy example. All requests sent to port 8000 are forwarded to port
# 8080, including HTTP/1.1 upgrade requests. Upgraded requests will have their
# dedicated TCP tunnel.

[[server]]

listen = "127.0.0.1:8000"
forward = "127.0.0.1:8080"

# Simple static files server example. This server will run in parallel with the
# one defined above, as the configuration file accepts multiple server
# instances on different ports.

[[server]]

listen = "127.0.0.1:9000"
serve = "/home/user/website"

# Complex server example. In this case, the server listens on multiple IP
# addresses, should load balance requests that start with "/api" between ports
# 8080 and 8081 and also serves files from a directory.

[[server]]

listen = ["127.0.0.1:8100", "192.168.1.2:8100"]

match = [
    { uri = "/api", forward = ["127.0.0.1:8080", "127.0.0.1:8081"] },
    { uri = "/", serve = "/home/user/website" },
]

# Weighted load balancing example using WRR (Weighted Round Robin) algorithm.
# With this configuration, from every 6 requests received by the proxy at port
# 8200, 1 will be forwarded to port 8080, 3 of them will be forwarded to port
# 8081 and 2 of them to port 8082.

[[server]]

listen = ["127.0.0.1:8200", "192.168.1.2:8200"]

[[server.forward]]

algorithm = "WRR" # This is the default, and this is also the only one for now.

backends = [
    { address = "127.0.0.1:8080", weight = 1 },
    { address = "127.0.0.1:8081", weight = 3 },
    { address = "127.0.0.1:8082", weight = 2 },
]

使用cargo启动服务器

cargo run

功能

  • HTTP Forwarded头(RFC 7239)。
  • 优雅关闭(在所有套接字关闭之前不要杀死进程)。
  • HTTP/1.1升级连接(类似于TCP隧道)。
  • HTTP Via头(RFC 5322的第3.6.7节)
  • HTTP/2
  • 静态文件服务器。
  • 在不同端口上的多个服务器,既有静态又有代理。
  • 头部自定义配置(见config.sketch.toml)。
  • 热重载(在不停止的情况下动态切换配置)。
  • 缓存。
  • 负载均衡。
  • 守护进程。
  • TLS。

依赖项

~5–12MB
~122K SLoC