> ## 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

> Complete reference of NATS server command-line flags

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

## Command Syntax

```bash theme={null}
nats-server [server-options]
```

## Server Options Reference

<ParamField path="-a, --addr, --net" type="string" default="0.0.0.0">
  Bind to host address. Specifies the network interface the server listens on for client connections.

  **Examples:**

  ```bash theme={null}
  # 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
  ```
</ParamField>

<ParamField path="-p, --port" type="number" default="4222">
  Use port for client connections. The default NATS client port is 4222.

  **Examples:**

  ```bash theme={null}
  # Use default port
  nats-server

  # Use custom port
  nats-server -p 4223

  # Random available port
  nats-server -p -1
  ```
</ParamField>

<ParamField path="-n, --name, --server_name" type="string" default="auto">
  Server name for identification. If not specified, a unique name is automatically generated.

  **Examples:**

  ```bash theme={null}
  # Auto-generated name
  nats-server

  # Custom server name
  nats-server -n nats-prod-01
  nats-server --server_name nats-east-1
  ```
</ParamField>

<ParamField path="-P, --pid" type="string">
  File to store the server's process ID. Useful for process management and sending signals.

  **Examples:**

  ```bash theme={null}
  nats-server -P /var/run/nats-server.pid
  nats-server --pid /tmp/nats.pid
  ```
</ParamField>

<ParamField path="-m, --http_port" type="number">
  Use port for HTTP monitoring endpoint. Enables the monitoring interface at `http://<host>:<port>/varz`, `/connz`, `/subsz`, etc.

  **Examples:**

  ```bash theme={null}
  # 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
</ParamField>

<ParamField path="-ms, --https_port" type="number">
  Use port for HTTPS monitoring. Same as `-m` but serves monitoring endpoints over HTTPS.

  **Examples:**

  ```bash theme={null}
  nats-server -ms 8223 --tlscert server-cert.pem --tlskey server-key.pem
  ```
</ParamField>

<ParamField path="-c, --config" type="string">
  Configuration file path. The configuration file uses a flexible format for complex setups.

  **Examples:**

  ```bash theme={null}
  # 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
  ```
</ParamField>

<ParamField path="-t" type="boolean">
  Test configuration and exit. Validates the configuration file without starting the server.

  **Examples:**

  ```bash theme={null}
  # Validate configuration
  nats-server -c nats.conf -t
  ```

  The server will print whether the configuration is valid and exit with status 0 on success.
</ParamField>

<ParamField path="-sl, --signal" type="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`, `reload`

  See [Signals](/cli/signals) for detailed usage.
</ParamField>

<ParamField path="--client_advertise" type="string">
  Client URL to advertise to other servers. Useful when the server is behind NAT or in containerized environments.

  **Examples:**

  ```bash theme={null}
  # 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
  ```
</ParamField>

<ParamField path="--ports_file_dir" type="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:**

  ```bash theme={null}
  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.
</ParamField>

## Complete Examples

### Basic Server

```bash theme={null}
nats-server -p 4222 -m 8222
```

### Production Server

```bash theme={null}
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

```bash theme={null}
nats-server -n dev-server -p 4223 -m 8223 -D
```

### Server Behind NAT

```bash theme={null}
nats-server \
  -a 0.0.0.0 \
  -p 4222 \
  --client_advertise nats://public-ip.example.com:4222
```

### Testing Configuration

```bash theme={null}
# Validate configuration
nats-server -c production.conf -t

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

## Related Options

* [Logging Options](/cli/logging-options) - Configure logging and debugging
* [Signals](/cli/signals) - Send signals to running server
