goproxy

module
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2021 License: MIT

README

GOproxy

PoC for learning how work proxy and load balancer like nginx server

GOproxy command

Build

make build

List of command available


  -backends string
        Load balanced backends, use commas to separate
  -genkey
        Action for generate hash for protected routes
  -portLB int
        Port to serve to run load balancing (default 3030)
  -portProxy int
        Port to serve to run proxy (default 5000)
  -prevkey string
        Action for save a previous hash for protected routes to validate JWT
  -type string
        Main Service default is proxy (default "proxy")

Start Proxy server first time

genkey command in true generate random secretkey and save on badgerdb on badger.data

./goproxy -portProxy 5000 -genkey true

prevkey command receive a custom secretkey and save this on badgerdb on badger.data

./goproxy -portProxy 5000 -prevkey <secretKey>

Start Proxy server

./goproxy -portProxy 5001

Start load balancer

./goproxy -type lb --backends "http://localhost:5000,http://localhost:5001,http://localhost:5002"

Start API PoC service

go run  services/micro-a/api.go --port <port>

Start static files server

go run cmd/goproxy.go -type static

Install badger db on window if you don`t use CGO

CGO_ENABLED=0 go get github.com/dgraph-io/badger/v3

Generate customs SSL (key,cert,pem,crs,cnf)


cd ssl

chmod +x ./generate.sh

./generate.sh

Generate SSL (throug let`s encrypt)

Check this post "Contratar un certificado SSL Gratis con Let's Encrypt y configurar Nginx" by @acoronado for more information.


apt-get install -y certbot

certbot certonly \
    -d midominio.com \
    --noninteractive \
    --standalone \
    --agree-tos \
    --register-unsafely-without-email

Then configure our goproxy.yaml and add the ssl files generated by certbot

# For SSL static server
  ssl_server:
    enable: true
    ssl_port: 8443
    crt_file: /etc/letsencrypt/live/mydomain.com/fullchain.pem
    key_file: /etc/letsencrypt/live/mydomain.com/privkey.pem
# For SSL proxy server
  ssl_proxy:
    enable: true
    ssl_port: 443
    crt_file: /etc/letsencrypt/live/mydomain.com/fullchain.pem
    key_file: /etc/letsencrypt/live/mydomain.com/privkey.pem

When the ssl certification was expired you need to renew all certificates with the following commnad

certbot renew

BenchMarking

ab -c 1000 -n 10000 http://localhost:5000/health

Directories

Path Synopsis
cmd
cli
examples
micro-a command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL