nats-io/nats-server · error
can't specify both HTTP (%v) and HTTPs (%v) ports
Error message
can't specify both HTTP (%v) and HTTPs (%v) ports
What it means
StartMonitoring rejects configs that set both the plain HTTP monitoring port and the HTTPS monitoring port; only one monitor listener may be configured. The message includes both conflicting port values.
Source
Thrown at server/server.go:3029
// DEPRECATED: Should use StartMonitoring.
func (s *Server) StartHTTPMonitoring() {
s.startMonitoring(false)
}
// StartHTTPSMonitoring will enable the HTTPS monitoring port.
// DEPRECATED: Should use StartMonitoring.
func (s *Server) StartHTTPSMonitoring() {
s.startMonitoring(true)
}
// StartMonitoring starts the HTTP or HTTPs server if needed.
func (s *Server) StartMonitoring() error {
// Snapshot server options.
opts := s.getOpts()
// Specifying both HTTP and HTTPS ports is a misconfiguration
if opts.HTTPPort != 0 && opts.HTTPSPort != 0 {
return fmt.Errorf("can't specify both HTTP (%v) and HTTPs (%v) ports", opts.HTTPPort, opts.HTTPSPort)
}
var err error
if opts.HTTPPort != 0 {
err = s.startMonitoring(false)
} else if opts.HTTPSPort != 0 {
if opts.TLSConfig == nil {
return fmt.Errorf("TLS cert and key required for HTTPS")
}
err = s.startMonitoring(true)
}
return err
}
// HTTP endpoints
const (
RootPath = "/"
VarzPath = "/varz"
ConnzPath = "/connz"View on GitHub (pinned to 3a66a489d2)
Solutions
- Keep only one: delete `http_port` if you want TLS monitoring, or delete `https_port` for plain HTTP
- Check the effective merged config (`nats-server --signal reload` logs, or start with -V) for both keys
- Audit systemd/CLI flags for a duplicate -m/--https_port
Example fix
// before
http_port: 8222
https_port: 8223
// after
https_port: 8223
tls { cert: "server.pem", key: "server-key.pem" } Defensive patterns
Strategy: validation
Validate before calling
// Reject double monitoring ports before server start
if cfg.HTTPPort != 0 && cfg.HTTPSPort != 0 {
return errors.New("configure only one of http_port or https_port for monitoring")
} Prevention
- Set exactly one of http_port / https_port in each config
- When overriding via flags, unset the conflicting config key
- Template monitoring config from a single variable so both ports can't be filled
When it happens
Trigger: Options contain both opts.HTTPPort != 0 and opts.HTTPSPort != 0, e.g. config with both `http_port: 8222` and `https_port: 8223`, or flags `-m 8222 --https_port 8223` combined.
Common situations: Merging two config files (one with http_port, one with https_port); flag-based overrides stacking on a config that already sets the other port; environment/templating filling both values.
Related errors
- TLS cert and key required for HTTPS
- failed to create mapping transform for stream import subject
- store operation not supported for URL Resolver
- delete must be enabled in server config
- Fetch timeout %v is too smal
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/376e3dac7fae3232.
Report an issue: GitHub.