Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nats-io/nats-server/llms.txt

Use this file to discover all available pages before exploring further.

Server options control the core behavior of the NATS server including network binding, monitoring, and server identification.

Command Syntax

nats-server [server-options]

Server Options Reference

-a, --addr, --net
string
default:"0.0.0.0"
Bind to host address. Specifies the network interface the server listens on for client connections.Examples:
# Listen on all interfaces (default)
nats-server -a 0.0.0.0

# Listen on localhost only
nats-server -a 127.0.0.1

# Listen on specific interface
nats-server -a 192.168.1.10
-p, --port
number
default:"4222"
Use port for client connections. The default NATS client port is 4222.Examples:
# Use default port
nats-server

# Use custom port
nats-server -p 4223

# Random available port
nats-server -p -1
-n, --name, --server_name
string
default:"auto"
Server name for identification. If not specified, a unique name is automatically generated.Examples:
# Auto-generated name
nats-server

# Custom server name
nats-server -n nats-prod-01
nats-server --server_name nats-east-1
-P, --pid
string
File to store the server’s process ID. Useful for process management and sending signals.Examples:
nats-server -P /var/run/nats-server.pid
nats-server --pid /tmp/nats.pid
-m, --http_port
number
Use port for HTTP monitoring endpoint. Enables the monitoring interface at http://<host>:<port>/varz, /connz, /subsz, etc.Examples:
# Enable monitoring on default monitoring port
nats-server -m 8222

# Custom monitoring port
nats-server -m 9090
Access monitoring endpoints:
  • http://localhost:8222/varz - General server information
  • http://localhost:8222/connz - Connection information
  • http://localhost:8222/subsz - Subscription information
-ms, --https_port
number
Use port for HTTPS monitoring. Same as -m but serves monitoring endpoints over HTTPS.Examples:
nats-server -ms 8223 --tlscert server-cert.pem --tlskey server-key.pem
-c, --config
string
Configuration file path. The configuration file uses a flexible format for complex setups.Examples:
# Load configuration file
nats-server -c /etc/nats/nats-server.conf
nats-server --config ./nats.conf

# Configuration with overrides
nats-server -c nats.conf -p 4223 -D
-t
boolean
Test configuration and exit. Validates the configuration file without starting the server.Examples:
# Validate configuration
nats-server -c nats.conf -t
The server will print whether the configuration is valid and exit with status 0 on success.
-sl, --signal
string
Send signal to nats-server process. Used for process management without direct PID access.Format: --signal <signal>[=<pid>]Signals: ldm, stop, quit, term, reopen, reloadSee Signals for detailed usage.
--client_advertise
string
Client URL to advertise to other servers. Useful when the server is behind NAT or in containerized environments.Examples:
# Advertise public IP
nats-server --client_advertise nats://public.example.com:4222

# Advertise with custom port
nats-server -p 4222 --client_advertise nats://10.0.1.5:4222
--ports_file_dir
string
Creates a ports file in the specified directory. The file is named <executable_name>_<pid>.ports and contains the actual ports the server is listening on.Examples:
nats-server --ports_file_dir /var/run/nats
This creates a file like /var/run/nats/nats-server_12345.ports containing:
nats-server: 4222
http: 8222
Useful when using -1 for random port assignment.

Complete Examples

Basic Server

nats-server -p 4222 -m 8222

Production Server

nats-server \
  -c /etc/nats/nats-server.conf \
  -P /var/run/nats-server.pid \
  -m 8222 \
  -l /var/log/nats-server.log

Development Server with Custom Name

nats-server -n dev-server -p 4223 -m 8223 -D

Server Behind NAT

nats-server \
  -a 0.0.0.0 \
  -p 4222 \
  --client_advertise nats://public-ip.example.com:4222

Testing Configuration

# Validate configuration
nats-server -c production.conf -t

# If valid, start the server
nats-server -c production.conf