fp-traefik
is a frps plugin
that enables the use of frp as a configuration discovery source for Traefik.
As an HTTP plugin for frps,
fp-traefik
will receive HTTP requests from frps when a frpc client connects to frps,
and set key-value pairs to Redis based on requests.
Traefik that connected to the same Redis server,
updates its dynamic configuration accordingly upon detecting changes in the key-value pairs.
-
Clone the repository and install dependencies
git clone https://github.com/Chihsiao/fp-traefik.git && cd fp-traefik poetry install
-
Configure environment variables
The configuration for
fp-traefik
is set through environment variables, which are listed below:-
FP_TRAEFIK_REDIS_URL
: Redis connection URL. -
FP_TRAEFIK_SUBDOMAIN_HOST
: Corresponds to thesubdomainHost
in frps. -
FP_TRAEFIK_DEFAULT_SERVICE
: Default service when no service is set for routers. -
FP_TRAEFIK_DEFAULT_ENTRYPOINT
: Default entry point when no entry point is set for routers. -
FP_TRAEFIK_DEFAULT_ROUTER_NAME_PREFIX
: Prefix used for the default router name when no router is set. -
FP_TRAEFIK_VERBOSE
: Controls the logging level; setting it totrue
enables debug mode. -
FP_TRAEFIK_EXPOSED_BY_DEFAULT
: Whether to autoconfigure proxies.- Can be overridden by
metadatas."traefik/enable"
in the frpc configuration.
- Can be overridden by
-
FP_TRAEFIK_ROOT_KEY
: Corresponds to theproviders.redis.rootKey
in Traefik.
-
-
Run the application
poetry run waitress fp_traefik.app:app
-
Integrate with frps and Traefik
-
Configure frps
Add the following configuration to the frps configuration file:
[[httpPlugins]] name = "fp_traefik" addr = "i_am_the_address_to_fp_traefik:8080" path = "/handler" ops = [ "NewProxy", "CloseProxy", "NewWorkConn", ]
-
Configure Traefik
Use the same Redis instance as the configuration source for
fp-traefik
, refer to Traefik & Redis for more details.
-
-
Set up frpc
Below is an example of a possible frpc configuration:
serverAddr = "frps" serverPort = 7000 [[proxies]] name = "whoami" localIP = "127.0.0.1" localPort = 80 type = "http" subdomain = "www" locations = ["/foo", "/bar"]
This will set the following key-value pairs in Redis:
SET "traefik/http/routesr/frp-whoami/service" "frp" SET "traefik/http/routers/frp-whoami/entryPoints/0" "web" SET "traefik/http/routers/frp-whoami/rule" "Host(`www.example.org`) && (PathPrefix(`/foo`) || PathPrefix(`/bar`))"
Currently, it only supports generating Traefik configurations for proxies whose type is
http
. However, you can usemetadatas
to set custom Traefik configurations, supporting any type of proxy, for example:serverAddr = "frps" serverPort = 7000 # ... [metadatas] # connection-level configuration "traefik/http/middlewares/enable-compression/compress" = "true" [[proxies]] # ... [proxies.metadatas] # proxy-level configuration "traefik/http/routers/frp-whoami/middlewares/0" = "enable-compression" "traefik/http/routers/frp-whoami/entryPoints/0" = "web-secure" "traefik/http/routers/frp-whoami/tls" = "true"
Connection-level metadata applies to the entire connection, while proxy-level metadata only affects the specific proxy.
The compose.yml provides a simple example to run fp-traefik
along with frps and Traefik.
This project is licensed under the MIT License. For more details, see the LICENSE file.