diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..3f65241 --- /dev/null +++ b/.env.sample @@ -0,0 +1,5 @@ +ADDR= +PROTO= +PEM= +KEY= +TIMEOUT= \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index 5d2aff9..bdbce41 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -43,6 +43,11 @@ nfpms: maintainer: "Achmad Irianto Eka Putra " license: "MIT" vendor: ryanbekhen + contents: + - src: systemd/nanoproxy.service + dst: /etc/systemd/system/nanoproxy.service + - src: .env.sample + dst: /etc/nanoproxy/nanoproxy.env formats: - deb - rpm @@ -52,9 +57,6 @@ release: archives: - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' - format_overrides: - - goos: windows - format: zip wrap_in_directory: true checksum: diff --git a/README.md b/README.md index 9733ce4..14b1f6f 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,23 @@ NanoProxy is a lightweight HTTP proxy server designed to provide basic proxying ### Installation +You have multiple options for installing NanoProxy: + +#### 1. Download from GitHub Releases + +You can download the latest release of NanoProxy from the +[GitHub Releases page](https://github.com/ryanbekhen/nanoproxy/releases). Choose the appropriate installer for your +operating system. + +#### 2. Build from Source + 1. Clone this repository: `git clone https://github.com/ryanbekhen/NanoProxy.git` 2. Navigate to the project directory: `cd NanoProxy` +3. Run the proxy server: `go build -o nanoproxy proxy.go` ### Usage -1. Run the proxy server: `go run proxy.go` +1. Run the proxy server: `./nanoproxy` 2. The proxy will start listening on the default address and port (:8080) and use default configuration values. ### Running on Docker @@ -38,7 +49,18 @@ You can modify the behavior of NanoProxy by adjusting the command line flags whe - `-proto`: Proxy protocol `http` or `https`. If set to `https`, the `-pem` and `-key` flags must be set. - `-timeout`: Timeout duration for tunneling connections (default: 15 seconds). -Modify these flags according to your requirements. +If you are installing NanoProxy locally, you can set the configuration using environment variables. Create a file +at `/etc/nanoproxy/nanoproxy.env` and add the desired values: + +```text +ADDR=:8080 +PROTO=http +PEM=server.pem +KEY=server.key +TIMEOUT=15s +``` + +Modify these flags or environment variables according to your requirements. ## Contributions diff --git a/config/config.go b/config/config.go index 5d68d22..95cf66d 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "flag" + "os" "time" ) @@ -21,5 +22,28 @@ func New() *Config { flag.StringVar(&c.Addr, "addr", ":8080", "proxy listen address (default :8080)") flag.DurationVar(&c.TunnelTimeout, "timeout", time.Second*15, "tunnel timeout (default 15s)") flag.Parse() + + if os.Getenv("PEM") != "" { + c.PemPath = os.Getenv("PEM") + } + + if os.Getenv("KEY") != "" { + c.KeyPath = os.Getenv("KEY") + } + + if os.Getenv("PROTO") != "" { + c.Proto = os.Getenv("PROTO") + } + + if os.Getenv("ADDR") != "" { + c.Addr = os.Getenv("ADDR") + } + + if os.Getenv("TIMEOUT") != "" { + d, err := time.ParseDuration(os.Getenv("TIMEOUT")) + if err == nil { + c.TunnelTimeout = d + } + } return c } diff --git a/systemd/nanoproxy.service b/systemd/nanoproxy.service new file mode 100644 index 0000000..2210912 --- /dev/null +++ b/systemd/nanoproxy.service @@ -0,0 +1,13 @@ +[Unit] +Description=NanoProxy is a simple reverse proxy written in Go +After=network.target + +[Service] +EnvironmentFile=/etc/nanoproxy/nanoproxy.env +ExecStart=/usr/bin/nanoproxy +WorkingDirectory=/usr/bin +Restart=always +User=root + +[Install] +WantedBy=multi-user.target \ No newline at end of file