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

> Core NATS server configuration options for connections, limits, and network settings

## Overview

Core server options control fundamental NATS server behavior including network binding, connection limits, payload sizes, and timeouts.

## Command Line Flags

### Network Configuration

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

  ```bash theme={null}
  nats-server -a 127.0.0.1
  ```
</ParamField>

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

  ```bash theme={null}
  nats-server -p 4222
  ```
</ParamField>

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

  ```bash theme={null}
  nats-server --server_name "nats-prod-01"
  ```
</ParamField>

<ParamField path="--client_advertise" type="string">
  Client URL to advertise to other servers. Useful when running behind NAT or load balancers.

  ```bash theme={null}
  nats-server --client_advertise "nats://public.example.com:4222"
  ```
</ParamField>

### Connection Limits

<ParamField path="max_connections" type="integer">
  Maximum number of concurrent client connections.

  **Config file:**

  ```conf theme={null}
  max_connections: 1000
  ```
</ParamField>

<ParamField path="max_subscriptions" type="integer">
  Maximum number of subscriptions per connection.

  **Config file:**

  ```conf theme={null}
  max_subscriptions: 0  # unlimited
  ```
</ParamField>

### Payload and Performance

<ParamField path="max_payload" type="integer" default="1048576">
  Maximum message payload size in bytes. Default is 1MB.

  **Config file:**

  ```conf theme={null}
  max_payload: 1048576  # 1 MB
  ```
</ParamField>

<ParamField path="max_pending" type="integer" default="67108864">
  Maximum number of bytes buffered for a connection. Default is 64MB.

  **Config file:**

  ```conf theme={null}
  max_pending: 67108864  # 64 MB
  ```
</ParamField>

<ParamField path="write_deadline" type="duration">
  Maximum time to wait when writing to a client connection.

  **Config file:**

  ```conf theme={null}
  write_deadline: "2s"
  ```
</ParamField>

### Monitoring

<ParamField path="-m, --http_port" type="integer">
  HTTP port for monitoring endpoints.

  ```bash theme={null}
  nats-server -m 8222
  ```
</ParamField>

<ParamField path="-ms, --https_port" type="integer">
  HTTPS port for monitoring with TLS.

  ```bash theme={null}
  nats-server -ms 8222
  ```
</ParamField>

### Other Options

<ParamField path="-P, --pid" type="string">
  File path to store process ID.

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

<ParamField path="-c, --config" type="string">
  Path to configuration file.

  ```bash theme={null}
  nats-server -c /etc/nats/nats-server.conf
  ```
</ParamField>

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

  ```bash theme={null}
  nats-server -c nats.conf -t
  ```
</ParamField>

<ParamField path="--ports_file_dir" type="string">
  Directory where a ports file will be created containing the server's listening ports. File format: `<executable_name>_<pid>.ports`.

  ```bash theme={null}
  nats-server --ports_file_dir /var/run/nats
  ```
</ParamField>

## Configuration File Example

```conf theme={null}
# Basic Server Configuration
host: "0.0.0.0"
port: 4222
server_name: "nats-prod-01"

# Connection Limits
max_connections: 1000
max_payload: 1048576     # 1 MB
max_pending: 67108864    # 64 MB
max_subscriptions: 0     # unlimited

# Timeouts
write_deadline: "2s"
ping_interval: "2m"
ping_max: 2

# Monitoring
http_port: 8222

# Logging
log_file: "/var/log/nats-server.log"
logtime: true
```

## Complete Server Example

Here's a production-ready configuration combining multiple server options:

```conf theme={null}
# Production NATS Server Configuration

# Network
host: "0.0.0.0"
port: 4222
server_name: "nats-prod-01"
client_advertise: "nats://public.example.com:4222"

# Limits
max_connections: 5000
max_payload: 2097152        # 2 MB
max_pending: 134217728      # 128 MB
max_control_line: 4096

# Timeouts
write_deadline: "5s"
ping_interval: "30s"
ping_max: 3

# Monitoring
http_port: 8222

# Logging
log_file: "/var/log/nats/nats-server.log"
log_size_limit: 104857600   # 100 MB
logtime: true
debug: false
trace: false

# PID file
pid_file: "/var/run/nats/nats-server.pid"
```

## Runtime Configuration

### Testing Configuration

Validate your configuration before starting the server:

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

### Starting with Options

Combine command line flags with a configuration file:

```bash theme={null}
nats-server -c nats-server.conf -p 4223 -D -V
```

Command line flags override configuration file values.

## Best Practices

1. **Connection Limits**: Set `max_connections` based on expected load and system resources
2. **Payload Size**: Increase `max_payload` if your application sends large messages
3. **Write Deadline**: Tune `write_deadline` based on network latency and client behavior
4. **Monitoring**: Always enable monitoring with `http_port` for production deployments
5. **Server Name**: Use descriptive server names in clusters for easier troubleshooting
6. **Client Advertise**: Configure when behind NAT or load balancers

## Related Configuration

<CardGroup cols={2}>
  <Card title="Cluster Options" icon="network-wired" href="/configuration/cluster-options">
    Configure server clustering and routes
  </Card>

  <Card title="JetStream Options" icon="database" href="/configuration/jetstream-options">
    Enable and configure JetStream persistence
  </Card>

  <Card title="TLS Options" icon="lock" href="/configuration/tls-options">
    Secure connections with TLS
  </Card>
</CardGroup>
