- Gnar
A Versatile Proxy Tool with Auto-HTTPS Subdomain Support.
Gnar is a powerful and flexible proxy tool, similar to frp, with built-in support for Auto-HTTPS subdomain proxying. It's designed to be simple yet feature-rich, making it an ideal solution for developers who need a reliable and secure proxy setup.
- Simple implementation with minimal third-party dependencies
- Client graceful shutdown.
- Support for TCP/UDP traffic forwarding
- Subdomain proxy using Caddy server
- Configurable via command-line flags or a configuration file
- Multi-client forwarding support
- Token-based authentication for enhanced security
- Server-side admin panel for easy management
- Integration of yamux for multiplexing connections
- Deployable on fly.io
git clone https://github.com/abcdlsj/gnar
make
-
Start the server: with positional argument:
gnar server 8910
with flag:
gnar server -p 8910
Or using a configuration file:
gnar server -c server_config.toml
-
Start the client: with positional argument:
gnar client localhost:8910 3000:9001
with flag:
gnar client -s localhost:8910 -p 3000:9001
Or using a configuration file:
gnar client -c client_config.toml
-
Start a sample service:
python3 -m http.server 3000
-
Access your service at
localhost:9001
Gnar supports both command-line flags and configuration files. Here's a sample client configuration:
Run gnar server with optional port argument
Usage:
gnar server [port] [flags]
Flags:
-a, --admin-port int admin server port
-s, --caddy-srv-name string caddy server name (default "srv0")
-c, --config string config file
-D, --domain string domain name
-d, --domain-tunnel enable domain tunnel
-h, --help help for server
-m, --multiplex multiplex client/server control connection
-p, --port int server port (default 8910)
-t, --token string token
Run gnar client with optional server address and port mapping
Usage:
gnar client [server-addr] [local-port:remote-port] [flags]
Flags:
-c, --config string config file
-h, --help help for client
-m, --multiplex multiplex client/server control connection
-n, --proxy-name string proxy name
-y, --proxy-type string proxy transport protocol type (default "tcp")
-s, --server-addr string server addr (default "localhost:8910")
--speed-limit string speed limit
-d, --subdomain string subdomain
-t, --token string token
server-addr = "localhost:8910"
token = "abcdlsj" # optional
multiplex = true # optional, if true will use yamux to multiplex the connection
[[proxys]]
proxy-name = "python_http_file_service" # optional
subdomain = "python3-http" # optional, if not set, will generate a random subdomain prefix
local-port = 3000
remote-port = 9001
speed-limit = "100kb" # optional, if not set, will not limit speed
proxy-type = "tcp"
[[proxys]]
local-port = 3001
remote-port = 9002
proxy-type = "tcp"port = 8910
admin-port = 8911
domain-tunnel = false
domain = "example.com"
# token = "abcdlsj" # optional
multiplex = falseThe server command accepts an optional port number as a positional argument:
gnar server [port]If not provided, the default port (8910) or the port specified in the configuration file will be used.
The client command accepts two optional positional arguments:
gnar client [server-addr] [local-port:remote-port]server-addr: The address of the gnar server (e.g., "localhost:8910")local-port:remote-port: The local and remote port mapping (e.g., "3000:9001")
If these arguments are not provided, the values from the configuration file or default values will be used.
Warning
This need you have the base knowledge of caddy and caddy plugin.
-
Set up your domain's DNS records:
A *.example.com <your server ip> A example.com <your server ip> -
Start the Caddy server(or if you have running caddy, you can skip this step):
caddy run --config <gnar path>/configs/caddy.json
-
Run the Gnar server with domain tunnel enabled:
gnar server 8910 -D example.com -d
can use
-sto set caddy server name(default should besrv0).gnar will use this name to create add new route.
if you use
Caddyfileto config caddy, you can usesudo caddy adapt --config /etc/caddy/Caddyfileto generate caddy.json. -
Start the client with a custom subdomain:
gnar client localhost:8910 3000:9001 -d myapp
Gnar can be easily deployed on https://fly.io.
Warning
I haven't tested it for a long time, it may need to be updated.
You can edit entrypoint.sh to start your own server you need to special set forward port.
Example:
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
app = "xxxx"
primary_region = "hkg"
[build]
# Control
[[services]]
internal_port = 8910
protocol = "tcp"
[[services.ports]]
port = 8910
# Admin
[[services]]
internal_port = 8911
protocol = "tcp"
[[services.ports]]
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
# Forward TCP
[[services]]
internal_port = 9000
protocol = "tcp"
[[services.ports]]
handlers = ["tls", "http"]
port = 9000Run with fly launch.
After deployment, you can view xxxx.fly.dev:9000 and then view your own internal server.
Gnar uses Viper to manage configuration, which allows for setting options via environment variables. The following environment variables are supported:
GNAR_PORT: Server portGNAR_ADMIN_PORT: Admin server portGNAR_DOMAIN_TUNNEL: Enable domain tunnel (true/false)GNAR_DOMAIN: Domain nameGNAR_TOKEN: Authentication tokenGNAR_MULTIPLEX: Enable connection multiplexing (true/false)
GNAR_TOKEN: Authentication tokenGNAR_MULTIPLEX: Enable connection multiplexing (true/false)
Environment variables take precedence over configuration files and command-line flags. To use an environment variable, prefix the uppercase option name with GNAR_. For example, to set the server port:
export GNAR_PORT=8080
gnar serverThis will start the server on port 8080, regardless of the default value or any value specified in a configuration file.
- subdomain proxy not work
make sure you have set the dns record to your server ip. if you use cloudflare, need to set dns_key in caddy.json.
We welcome contributions to Gnar! Please read our Contributing Guidelines for more information on how to get started.
Thanks to JetBrains for providing free licenses to support this project.
Gnar is released under the MIT License.

