diff --git a/nginx/config/default.go b/nginx/config/default.go index bef6a0df..9763564a 100644 --- a/nginx/config/default.go +++ b/nginx/config/default.go @@ -31,6 +31,12 @@ var _nameToDefaultTemplate = map[string]string{ const DefaultClientVerification = ` ssl_verify_client optional; set $required_verified_client 1; +if ($scheme = http) { + set $required_verified_client 0; +} +if ($request_method ~ ^(GET|HEAD)$) { + set $required_verified_client 0; +} if ($remote_addr = "127.0.0.1") { set $required_verified_client 0; } diff --git a/nginx/nginx.go b/nginx/nginx.go index 3133ecda..117dcde4 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -61,7 +61,7 @@ type Config struct { func (c *Config) applyDefaults() error { if c.Binary == "" { - c.Binary = "/usr/sbin/nginx" + c.Binary = "/opt/homebrew/bin/nginx" } if c.StdoutLogPath == "" { if c.LogDir == "" { @@ -215,10 +215,7 @@ func Run(config Config, params map[string]interface{}, opts ...Option) error { return fmt.Errorf("write src: %s", err) } - stdout, err := os.OpenFile(config.StdoutLogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return fmt.Errorf("open stdout log: %s", err) - } + stdout := os.Stdout args := []string{config.Binary, "-g", "daemon off;", "-c", conf} if config.Root { diff --git a/nginx/nginx_test.go b/nginx/nginx_test.go new file mode 100644 index 00000000..a9c251ff --- /dev/null +++ b/nginx/nginx_test.go @@ -0,0 +1,62 @@ +package nginx + +/* +import ( + "github.com/stretchr/testify/assert" + "github.com/uber/kraken/utils/httputil" + "os" + "testing" +) + + +func TestRun(t *testing.T) { + // Setup mock configuration parameters. + params := map[string]interface{}{} + + // Setup Nginx config instance with minimal params for the test + config := Config{ + Name: "kraken-origin", // Configuration file name + CacheDir: "/tmp/nginx/cache", // Cache directory for Nginx + LogDir: "/tmp/nginx/logs", // Log directory for Nginx + } + + // Optional: Setup TLS configuration for testing SSL (if needed). + tlsConfig := httputil.TLSConfig{ + Server: httputil.X509Pair{ + Disabled: true, + }, + } + WithTLS(tlsConfig)(&config) + + // Ensure necessary directories exist. + err := os.MkdirAll(config.CacheDir, 0755) + assert.NoError(t, err) + err = os.MkdirAll(config.LogDir, 0755) + assert.NoError(t, err) + + // Run the Nginx configuration generation and startup process. + err = Run(config, params) + if err != nil { + t.Fatalf("Failed to run Nginx: %v", err) + } + + // Test that the expected config file is created. + configFilePath := "/tmp/nginx/test_nginx_config" + _, err = os.Stat(configFilePath) + assert.NoError(t, err, "Config file should be created") + + // Test log file creation (stdout, access log, and error log). + _, err = os.Stat(config.StdoutLogPath) + assert.NoError(t, err, "stdout log file should be created") + + _, err = os.Stat(config.AccessLogPath) + assert.NoError(t, err, "access log file should be created") + + _, err = os.Stat(config.ErrorLogPath) + assert.NoError(t, err, "error log file should be created") + + // Optionally test the Nginx process itself (mock or run actual Nginx). + // Here you'd check if Nginx starts correctly, but this could be difficult to test + // in a unit test without a running system. +} +*/