Skip to content

Commit

Permalink
feat: Added Linux daemon support
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbekhen committed Aug 28, 2023
1 parent 6b9731b commit 31ecae5
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ADDR=
PROTO=
PEM=
KEY=
TIMEOUT=
8 changes: 5 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ nfpms:
maintainer: "Achmad Irianto Eka Putra <[email protected]>"
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
Expand All @@ -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:
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
24 changes: 24 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"flag"
"os"
"time"
)

Expand All @@ -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
}
13 changes: 13 additions & 0 deletions systemd/nanoproxy.service
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 31ecae5

Please sign in to comment.