Skip to content

Redirect to backend server that has the file - no more four-o-four!

License

Notifications You must be signed in to change notification settings

tb0hdan/SearchProxy

Repository files navigation

SearchProxy

Build Status GoDoc Go Report Card FOSSA Status

Redirect to backend server that has the file - no more four-o-four!

This project offers functionality similar to HAProxy/Nginx though it checks for file presence before returning redirect to respective backend server. Started as a frontend for opensource mirrors but can be used for other things like CDN.

Backend server selection algorithms so far:

  • First available server (the're sorted by latency during app startup). YAML value: first
  • The one closest to client (if none are good, fallback to first available). YAML value: closest
  • Least connections (load balanced). YAML value: leastconn
  • GeoBalance - combined approach. Three closest mirrors are rotated based on connections amount. YAML value: geobalance

Can be configured via YAML (with default being first available):

mirrors:
  - name: "gentoo"
    prefix: "/gentoo"
    algorithm: "closest"
    urls:
      - "http://gentoo.mirrors.tera-byte.com/"

Running

make dockerimage

docker run -p 8000:8000 tb0hdan/searchproxy

To confirm that SearchProxy returns link to file:

wget --spider http://localhost:8000/gentoo/distfiles/01-iosevka-1.14.1.zip

HTTP proxy support

SearchProxy uses Go's built-in http client with HTTP proxy support. In order to send all requests through a proxy, export environment variable like this:

export HTTP_PROXY=http://example.com:8000

GeoIP notice

This project uses GeoIP2-Golang which in turn relies on MaxMind's GeoLite database

Expected GeoIP DB file: GeoLite2-City.mmdb

Debugging

Debug is enabled using -debug command switch. In this mode net/http/pprof endpoints are exposed at their usual locations. See pprof page for more info.

CPU profile can be generated by adding -cpuprofile=filename command switch. File contents will be written upon program shutdown. This toggles -debug switch as well.

Thanks

Docker Golang