Skip to content

Plugins for getting information from ip2location database and redirect to specific url

Notifications You must be signed in to change notification settings

jiangwennn/traefik-plugin-ip2location-redirect

Repository files navigation

ip2location redirect

Plugins for getting the country code of the client ip from ip2location database and redirect to specific url when (no)match the target countries

Configuration

To configure this plugin you should add its configuration to the Traefik dynamic configuration as explained here. The following snippet shows how to configure this plugin with the File provider in TOML and YAML:

Static:

experimental:
  pilot:
    token: xxx

  plugins:
    ip2location_redirect:
      modulename: github.com/jiangwennn/traefik-plugin-ip2location-redirect
      version: v0.1.0

Dynamic:

http:
  middlewares:
    my-plugin:
      plugin:
        ip2location_redirect:
          filename: path/to/database.bin
          regions: ["CN"],
          redirectUrl: "https://github.com"
          noMatch: false # optional
          permanent: false # optional
          fromHeader: X-User-IP # optional
          disableErrorHeader: false # optional

Options

Filename

filename | string | Required

The path to ip2location database file (in binary format), and it must be in the working directory of the process running the Traefik binary

Regions

regions | []string | Required

Array of country codes in 2 letters, eg: CN,UK

RedirectUrl

redirectUrl | string | Required

The url address redirect to

NoMatch

noMatch | bool | Default: false

If true, redirect action performs when the ip doesn't belong to any of the regions configured

Permanent

permanent | bool | Default: false

If true, redirect status code will be 301 Moved Permanently, otherwise 302 Found

FromHeader

fromHeader | string | Default: empty

If defined, IP address will be obtained from this HTTP header. Remote-Addr By default.

DisableErrorHeader

disableErrorHeader | bool | Default: false

Errors

If any error occurred, this error will be placed to X-IP2LOCATION-REDIRECT-ERROR header

Reference

About

Plugins for getting information from ip2location database and redirect to specific url

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages