Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pcfens/redirector
https://github.com/pcfens/redirector
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pcfens/redirector
- Owner: pcfens
- Created: 2017-09-12T03:04:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-13T15:30:43.000Z (over 7 years ago)
- Last Synced: 2024-10-26T22:15:45.786Z (3 months ago)
- Language: Go
- Size: 800 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Redirector
==========A simple webserver that only redirects traffic based on a YAML configuration
file.## Configuration
A sample configuration file is available in config.yaml. Each value
can also be overridden with an environment variable.```yaml
---
bind_address: 0.0.0.0:8080
redirects:
- rules.yaml
```The bind address is the address and port that the HTTP server should listen to.
The value can also be set by setting the `BIND_ADDRESS` environment variable.The redirects array is evaluated in the order that files appear in the list.
Files can be local or remote (http and https only for now). The environment
variable `REDIRECT_SOURCE` can also be used, with multiple values separated
by commas.## Redirect Rules
Each redirect rule has a name, a match pattern, and one or more targets.
To redirect blahblahblah.com (with an optional leading www) to
somethingdifferent.com using a 301 redirect you would use
```yaml
- name: Blah Test
pattern: ^(www\.)?blahblahblah.com\/
targets:
- target: https://somethingdifferent.com/
code: 301
```### By Source IP
You can get more complex and redirect based on the source IP address (as
reported in the X-Forwareded-For header) too:
```yaml
- name: TV
pattern: ^tv\.university\.edu/
targets:
- target: https://contour.university.edu
code: 302
when:
source:
- 10.0.0.0/8
- 192.168.1.0/24
- target: https://google.com
code: 302
```The above example essentially says redirect tv.university.edu to
contour.university.edu when inside one of the two source IP ranges, otherwise
redirect to google.com. Whenever multiple targets are used you should use
302 redirects to avoid browsers caching the redirects.### Substitutions
Because everything is stored as regular expressions, substitutions are also
possible:
```yaml
- name: All to SSL
pattern: ^(www\.)?(?P[a-zA-Z0-9\-]+).com\/
targets:
- target: https://${name}.university.edu/
code: 301
```### Fall Back
Regular expressions are evaluated in the order they appear in the configuration
file. You should consider having some sort of catch all resource at the bottom
to prevent dead end 404s.### Reloading
Redirect rules can be reloaded without restarting the application by sending
an HTTP GET request to `/reload`.## Docker
Everything should work well under Docker without having to modify the base
image (using remote redirect rules with environment variables). An image is
available on the hub at
[pcfens/redirector](https://hub.docker.com/r/pcfens/redirector/tags/).