diff --git a/README.md b/README.md index 88ce0632..87ecdb64 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Sample SQL scripts to create the required database structure can be found insite The `sftpgo.conf` configuration file contains the following sections: - **"sftpd"**, the configuration for the SFTP server - - `bind_port`, integer the port used for serving SFTP requests. Default: 2022 + - `bind_port`, integer. The port used for serving SFTP requests. Default: 2022 - `bind_address`, string. Leave blank to listen on all available network interfaces. Default: "" - `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. Default: 15 - `max_auth_tries` integer. Maximum number of authentication attempts permitted per connection. If set to a negative number, the number of attempts are unlimited. If set to zero, the number of attempts are limited to 6. @@ -89,7 +89,7 @@ The `sftpgo.conf` configuration file contains the following sections: - `manage_users`, integer. Set to 0 to disable users management, 1 to enable - `track_quota`, integer. Set to 0 to disable quota tracking, 1 to update the used quota each time a user upload or delete a file - **"httpd"**, the configuration for the HTTP server used to serve REST API - - `bind_port`, integer the port used for serving HTTP requests. Default: 8080 + - `bind_port`, integer. The port used for serving HTTP requests. Set to 0 to disable HTTP server. Default: 8080 - `bind_address`, string. Leave blank to listen on all available network interfaces. Default: "127.0.0.1" Here is a full example showing the default config: diff --git a/main.go b/main.go index ac48ca67..e3723721 100644 --- a/main.go +++ b/main.go @@ -49,10 +49,8 @@ func main() { dataProvider := dataprovider.GetProvider() sftpdConf := config.GetSFTPDConfig() httpdConf := config.GetHTTPDConfig() - router := api.GetHTTPRouter() sftpd.SetDataProvider(dataProvider) - api.SetDataProvider(dataProvider) shutdown := make(chan bool) @@ -64,20 +62,27 @@ func main() { shutdown <- true }() - go func() { - logger.Debug(logSender, "initializing HTTP server with config %+v", httpdConf) - s := &http.Server{ - Addr: fmt.Sprintf("%s:%d", httpdConf.BindAddress, httpdConf.BindPort), - Handler: router, - ReadTimeout: 300 * time.Second, - WriteTimeout: 300 * time.Second, - MaxHeaderBytes: 1 << 20, // 1MB - } - if err := s.ListenAndServe(); err != nil { - logger.Error(logSender, "could not start HTTP server: %v", err) - } - shutdown <- true - }() + if httpdConf.BindPort > 0 { + router := api.GetHTTPRouter() + api.SetDataProvider(dataProvider) + + go func() { + logger.Debug(logSender, "initializing HTTP server with config %+v", httpdConf) + s := &http.Server{ + Addr: fmt.Sprintf("%s:%d", httpdConf.BindAddress, httpdConf.BindPort), + Handler: router, + ReadTimeout: 300 * time.Second, + WriteTimeout: 300 * time.Second, + MaxHeaderBytes: 1 << 20, // 1MB + } + if err := s.ListenAndServe(); err != nil { + logger.Error(logSender, "could not start HTTP server: %v", err) + } + shutdown <- true + }() + } else { + logger.Debug(logSender, "HTTP server not started, disabled in config file") + } <-shutdown }