Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ vim config.toml
go run cmd/sea/main.go > sea.conf
```

Set `logging_enabled = false` in `config.toml` if you want to disable NGINX
access and error logs for the server blocks.

### TLS / Let's Encrypt

If you want to run SEA behind HTTPS using Certbot, set `listen_ssl`,
Expand Down
8 changes: 5 additions & 3 deletions cmd/sea/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
SSLCertificateKey string `toml:"ssl_certificate_key"`
LetsEncrypt bool `toml:"letsencrypt"`
RedirectHTTP bool `toml:"redirect_http"`
LoggingEnabled bool `toml:"logging_enabled"`
CustomKeywords []KeywordRule `toml:"custom_keywords"`
}

Expand Down Expand Up @@ -61,9 +62,10 @@ func main() {

func loadConfig(path string) (Config, error) {
cfg := Config{
Listen: 80,
ListenSSL: 0,
ServerName: "search.localhost",
Listen: 80,
ListenSSL: 0,
ServerName: "search.localhost",
LoggingEnabled: true,
}
data, err := os.ReadFile(path)
if err != nil {
Expand Down
20 changes: 16 additions & 4 deletions cmd/sea/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ server_name = "example.com"

redirect_http = true

logging_enabled = false

ssl_certificate = "/tmp/full.pem"
ssl_certificate_key = "/tmp/key.pem"
letsencrypt = true
Expand Down Expand Up @@ -52,6 +54,9 @@ dest = "google"`)
if !cfg.LetsEncrypt {
t.Error("expected letsencrypt true")
}
if cfg.LoggingEnabled {
t.Error("expected logging_enabled false")
}
if cfg.ServerName != "example.com" {
t.Errorf("expected server name example.com, got %s", cfg.ServerName)
}
Expand All @@ -65,10 +70,11 @@ dest = "google"`)

func TestGenerateNginx(t *testing.T) {
cfg := Config{
Listen: 8080,
ListenSSL: 8443,
ServerName: "example.com",
RedirectHTTP: true,
Listen: 8080,
ListenSSL: 8443,
ServerName: "example.com",
LoggingEnabled: false,
RedirectHTTP: true,
CustomKeywords: []KeywordRule{{
Phrase: "foo",
Dest: "google",
Expand All @@ -87,4 +93,10 @@ func TestGenerateNginx(t *testing.T) {
if !strings.Contains(out, "~*(?i)^foo$") {
t.Errorf("generated config missing custom rule: %s", out)
}
if !strings.Contains(out, "access_log off;") {
t.Errorf("generated config missing access log disable: %s", out)
}
if !strings.Contains(out, "error_log /dev/null crit;") {
t.Errorf("generated config missing error log disable: %s", out)
}
}
16 changes: 16 additions & 0 deletions cmd/sea/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ server {
listen {{ .ListenSSL }} ssl http2;
listen [::]:{{ .ListenSSL }} ssl http2;
server_name {{ .ServerName }};
{{- if not .LoggingEnabled }}
access_log off;
error_log /dev/null crit;
{{- end }}
keepalive_timeout 5;
{{- if .SSLCertificate }}
ssl_certificate {{ .SSLCertificate }};
Expand All @@ -71,6 +75,10 @@ server {
listen {{ .Listen }};
listen [::]:{{ .Listen }};
server_name {{ .ServerName }};
{{- if not .LoggingEnabled }}
access_log off;
error_log /dev/null crit;
{{- end }}

return 404;
}
Expand All @@ -79,6 +87,10 @@ server {
listen {{ .Listen }};
listen [::]:{{ .Listen }};
server_name {{ .ServerName }};
{{- if not .LoggingEnabled }}
access_log off;
error_log /dev/null crit;
{{- end }}

location / {
return 302 $sea_target;
Expand All @@ -90,6 +102,10 @@ server {
listen {{ .Listen }};
listen [::]:{{ .Listen }};
server_name {{ .ServerName }};
{{- if not .LoggingEnabled }}
access_log off;
error_log /dev/null crit;
{{- end }}

location / {
return 302 $sea_target;
Expand Down
1 change: 1 addition & 0 deletions config-example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
listen = 80
listen_ssl = 443
server_name = "your.site"
# logging_enabled = true
# ssl_certificate = "/etc/letsencrypt/live/your.site/fullchain.pem"
# ssl_certificate_key = "/etc/letsencrypt/live/your.site/privkey.pem"
# letsencrypt = true
Expand Down