nginx-discovery 0.3.0

Discover and introspect NGINX configurations with ease
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
# nginx-discover CLI Guide

Complete guide for the `nginx-discover` command-line interface.

## Table of Contents

- [Installation]#installation
- [Quick Start]#quick-start
- [Global Options]#global-options
- [Commands]#commands
  - [parse]#parse---parse-and-validate-configuration
  - [extract]#extract---extract-information
  - [export]#export---export-configuration
  - [doctor]#doctor---health-check
- [Examples]#examples
- [Output Formats]#output-formats
- [Tips & Tricks]#tips--tricks
- [Troubleshooting]#troubleshooting

## Installation

### From Source

```bash
# Clone the repository
git clone https://github.com/urwithajit9/nginx-discovery.git
cd nginx-discovery

# Build with CLI feature
cargo build --release --features cli

# Install globally
cargo install --path . --features cli

# Or copy to system path
sudo cp ./target/release/nginx-discover /usr/local/bin/
```

### Verify Installation

```bash
nginx-discover --version
nginx-discover --help
```

## Quick Start

```bash
# Run health check
sudo nginx-discover doctor

# Parse your NGINX configuration
sudo nginx-discover parse --tree

# Extract all servers
sudo nginx-discover extract servers

# Export to JSON
sudo nginx-discover export json --pretty
```

> **Note:** Many commands require `sudo` to access NGINX configuration files and test configuration syntax.

## Global Options

These options are available for all commands:

```
-c, --config <PATH>      Path to nginx.conf (auto-detected if not specified)
-v, --verbose            Enable verbose output
-q, --quiet              Suppress all output except errors
--color <WHEN>           When to use color (auto, always, never)
-h, --help               Show help
-V, --version            Show version
```

### Examples

```bash
# Use specific config file
nginx-discover --config /custom/path/nginx.conf parse

# Verbose output
nginx-discover --verbose extract servers

# No colors (for piping)
nginx-discover --color never extract logs

# Quiet mode
nginx-discover --quiet doctor
```

## Commands

### `parse` - Parse and Validate Configuration

Parse and display NGINX configuration structure.

#### Usage

```bash
nginx-discover parse [OPTIONS]
```

#### Options

```
-t, --tree       Display configuration as a tree
-s, --summary    Show summary only
    --json       Output as JSON
```

#### Examples

**Display tree and summary (default):**

```bash
sudo nginx-discover parse
```

Output:
```
Configuration Tree:

└─ user www-data;
└─ worker_processes auto;
└─ http {
  ├─ access_log /var/log/nginx/access.log;
  └─ server {
    ├─ listen 80;
    └─ server_name example.com;
    }
  }

=== Configuration Summary ===

  Total directives: 15
  Server blocks: 2
    - SSL enabled: 1
    - HTTP only: 1
  Listening ports: [80, 443]
  Access logs: 2
  Log formats: 1
  Location blocks: 5
    - Proxy locations: 2

✓ Configuration parsed successfully
```

**Tree view only:**

```bash
sudo nginx-discover parse --tree
```

**Summary only:**

```bash
sudo nginx-discover parse --summary
```

**Export AST as JSON:**

```bash
sudo nginx-discover parse --json > ast.json
```

---

### `extract` - Extract Information

Extract specific information from NGINX configuration.

#### Subcommands

- `servers` - Extract server blocks
- `logs` - Extract log configurations
- `locations` - Extract location blocks

---

#### `extract servers` - Extract Server Blocks

```bash
nginx-discover extract servers [OPTIONS]
```

**Options:**

```
    --ssl-only           Show only SSL-enabled servers
    --port <PORT>        Filter by port number
    --name <NAME>        Filter by server name (supports wildcards)
-f, --format <FORMAT>    Output format (table, json, yaml, csv) [default: table]
-o, --output <FILE>      Write to file instead of stdout
```

**Examples:**

```bash
# Show all servers in table format
sudo nginx-discover extract servers
```

Output:
```
╭─────────────────────────┬──────┬─────┬────────────┬───────────╮
│ Server Name             │ Port │ SSL │ Locations  │ Default   │
├─────────────────────────┼──────┼─────┼────────────┼───────────┤
│ example.com             │ 80   │ No  │ 3          │ No        │
│ api.example.com         │ 443  │ Yes │ 5          │ No        │
│ secure.example.com      │ 443  │ Yes │ 2          │ Yes       │
╰─────────────────────────┴──────┴─────┴────────────┴───────────╯

Total: 3 servers (2 with SSL)
```

**Show only SSL servers:**

```bash
sudo nginx-discover extract servers --ssl-only
```

**Filter by port:**

```bash
sudo nginx-discover extract servers --port 443
```

**Filter by name with wildcards:**

```bash
# All subdomains of example.com
sudo nginx-discover extract servers --name "*.example.com"

# Servers ending with .api.com
sudo nginx-discover extract servers --name "*.api.com"
```

**Export as JSON:**

```bash
sudo nginx-discover extract servers --format json --output servers.json
```

**Export as CSV:**

```bash
sudo nginx-discover extract servers --format csv > servers.csv
```

---

#### `extract logs` - Extract Log Configurations

```bash
nginx-discover extract logs [OPTIONS]
```

**Options:**

```
    --with-formats       Include log format definitions
    --context <CONTEXT>  Filter by context (http, server, location)
-f, --format <FORMAT>    Output format (table, json, yaml, csv) [default: table]
-o, --output <FILE>      Write to file
```

**Examples:**

```bash
# Show all access logs
sudo nginx-discover extract logs
```

Output:
```
╭──────────────────────────────────────┬──────────┬────────────────╮
│ Log File                             │ Format   │ Context        │
├──────────────────────────────────────┼──────────┼────────────────┤
│ /var/log/nginx/access.log            │ combined │ Http           │
│ /var/log/nginx/api-access.log        │ json     │ Server("api")  │
│ /var/log/nginx/app.log               │ main     │ Location("/")  │
╰──────────────────────────────────────┴──────────┴────────────────╯

Total: 3 log files
```

**Include format definitions:**

```bash
sudo nginx-discover extract logs --with-formats
```

Output includes:
```
Log Formats:

  main:
    Variables: remote_addr, remote_user, time_local, request, status

  json:
    Variables: remote_addr, time_local, request, status, body_bytes_sent
```

**Filter by context:**

```bash
# Only server-level logs
sudo nginx-discover extract logs --context server

# Only location-level logs
sudo nginx-discover extract logs --context location
```

**Export for log collection tool:**

```bash
# Generate JSON for Fluentd/Vector configuration
sudo nginx-discover extract logs --with-formats --format json -o logs-config.json
```

---

#### `extract locations` - Extract Location Blocks

```bash
nginx-discover extract locations [OPTIONS]
```

**Options:**

```
    --proxy-only         Show only proxy locations
    --static-only        Show only static file locations
    --server <NAME>      Filter by server name
-f, --format <FORMAT>    Output format (table, json, yaml, csv) [default: table]
-o, --output <FILE>      Write to file
```

**Examples:**

```bash
# Show all locations
sudo nginx-discover extract locations
```

Output:
```
╭─────────────────┬──────────┬──────────┬────────┬──────────────────────────╮
│ Server          │ Path     │ Modifier │ Type   │ Target                   │
├─────────────────┼──────────┼──────────┼────────┼──────────────────────────┤
│ example.com     │ /        │ None     │ Static │ /var/www/html            │
│ example.com     │ /api     │ None     │ Proxy  │ http://backend:3000      │
│ api.example.com │ /v1      │ None     │ Proxy  │ http://api-v1:8080       │
│ api.example.com │ /static  │ PrefixP… │ Static │ /var/www/static          │
╰─────────────────┴──────────┴──────────┴────────┴──────────────────────────╯

Total: 4 locations
```

**Show only proxy locations:**

```bash
sudo nginx-discover extract locations --proxy-only
```

**Show only static file locations:**

```bash
sudo nginx-discover extract locations --static-only
```

**Filter by server:**

```bash
sudo nginx-discover extract locations --server api.example.com
```

**Generate service map:**

```bash
# Export all proxy locations as JSON for service discovery
sudo nginx-discover extract locations --proxy-only --format json -o service-map.json
```

---

### `export` - Export Configuration

Export entire configuration to different formats.

#### Usage

```bash
nginx-discover export <FORMAT> [OPTIONS]
```

#### Formats

- `json` - Export as JSON
- `yaml` - Export as YAML

#### Options

```
-o, --output <FILE>    Output file (stdout if not specified)
    --pretty           Pretty-print output (for JSON/YAML)
```

#### Examples

**Export to JSON:**

```bash
sudo nginx-discover export json --pretty
```

**Export to file:**

```bash
sudo nginx-discover export json --pretty --output config.json
sudo nginx-discover export yaml --output config.yaml
```

**Compact JSON (no pretty-print):**

```bash
sudo nginx-discover export json > config.min.json
```

**Use exported config:**

```bash
# Export and process with jq
sudo nginx-discover export json | jq '.directives[] | select(.name == "server")'

# Export and convert YAML to JSON
sudo nginx-discover export yaml | yq eval -o=json > config.json
```

---

### `doctor` - Health Check

Run diagnostics and health checks on NGINX configuration.

#### Usage

```bash
nginx-discover doctor [OPTIONS]
```

#### Options

```
    --no-network    Skip network checks
    --fix           Attempt to fix issues automatically (not yet implemented)
```

#### Checks Performed

1. ✓ NGINX binary found
2. ✓ Configuration file readable
3. ✓ Configuration syntax valid (nginx -t)
4. ✓ Configuration parseable by nginx-discovery
5. ✓ Log files and directories accessible
6. ✓ SSL certificates present

#### Examples

**Run all checks:**

```bash
sudo nginx-discover doctor
```

Output:
```
Running diagnostics...

✓ NGINX binary found: /usr/sbin/nginx (nginx version: nginx/1.24.0)
✓ Configuration file: /etc/nginx/nginx.conf
✓ Configuration syntax: valid
✓ Configuration parsed successfully
⚠ Log files: 1 warnings (Log directory does not exist: /var/log/custom/)
✓ SSL servers: 2 configured

=== Summary ===

  5 checks passed
  1 warnings
  0 errors

Passed with warnings
```

**Skip network checks:**

```bash
sudo nginx-discover doctor --no-network
```

**Exit codes:**

- `0` - All checks passed
- `1` - One or more checks failed

Use in scripts:
```bash
if sudo nginx-discover doctor --quiet; then
    echo "Configuration is healthy"
    sudo nginx -s reload
else
    echo "Configuration has issues!"
    exit 1
fi
```

---

## Examples

### DevOps Workflows

#### 1. Pre-Deployment Validation

```bash
#!/bin/bash
# validate-nginx.sh

echo "Validating NGINX configuration..."

# Run health check
if ! sudo nginx-discover doctor --quiet; then
    echo "❌ Configuration validation failed"
    exit 1
fi

# Check for SSL certificates
SSL_COUNT=$(sudo nginx-discover extract servers --ssl-only --format json | jq '. | length')
if [ "$SSL_COUNT" -gt 0 ]; then
    echo "✓ Found $SSL_COUNT SSL-enabled servers"
fi

# Extract and validate log paths
sudo nginx-discover extract logs --format json -o /tmp/logs.json
echo "✓ Configuration validated successfully"
```

#### 2. Infrastructure Inventory

```bash
#!/bin/bash
# inventory.sh - Generate infrastructure inventory

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
OUTPUT_DIR="inventory_$TIMESTAMP"

mkdir -p "$OUTPUT_DIR"

# Extract all information
sudo nginx-discover extract servers --format json -o "$OUTPUT_DIR/servers.json"
sudo nginx-discover extract logs --with-formats --format json -o "$OUTPUT_DIR/logs.json"
sudo nginx-discover extract locations --format json -o "$OUTPUT_DIR/locations.json"

# Generate summary
sudo nginx-discover parse --summary > "$OUTPUT_DIR/summary.txt"

# Create service map
sudo nginx-discover extract locations --proxy-only --format json -o "$OUTPUT_DIR/service-map.json"

echo "Inventory generated in $OUTPUT_DIR/"
```

#### 3. Log Collector Configuration

```bash
#!/bin/bash
# generate-fluentd-config.sh

# Extract log configurations
sudo nginx-discover extract logs --with-formats --format json -o nginx-logs.json

# Generate Fluentd configuration
cat > fluentd.conf << 'EOF'
# Auto-generated Fluentd configuration for NGINX logs
EOF

# Parse JSON and generate Fluentd sources
jq -r '.logs[] | @json' nginx-logs.json | while read -r log; do
    PATH=$(echo "$log" | jq -r '.path')
    FORMAT=$(echo "$log" | jq -r '.format_name // "combined"')

    cat >> fluentd.conf << EOF

<source>
  @type tail
  path $PATH
  tag nginx.access
  <parse>
    @type nginx
  </parse>
</source>
EOF
done

echo "Fluentd configuration generated: fluentd.conf"
```

#### 4. Security Audit

```bash
#!/bin/bash
# security-audit.sh

echo "=== NGINX Security Audit ==="
echo

# Check SSL configuration
echo "SSL/TLS Servers:"
sudo nginx-discover extract servers --ssl-only --format table

# Check for default servers
echo -e "\nChecking for default servers..."
sudo nginx-discover extract servers --format json | \
    jq '.[] | select(.listen[].default_server == true) | .server_names[0]'

# List all listening ports
echo -e "\nOpen Ports:"
sudo nginx-discover parse --summary | grep "Listening ports"

# Check for proxy locations
echo -e "\nProxy Endpoints:"
sudo nginx-discover extract locations --proxy-only --format table
```

#### 5. Configuration Monitoring

```bash
#!/bin/bash
# monitor-config-changes.sh

BASELINE="config-baseline.json"
CURRENT="config-current.json"

# Create baseline on first run
if [ ! -f "$BASELINE" ]; then
    sudo nginx-discover export json --pretty -o "$BASELINE"
    echo "Baseline created: $BASELINE"
    exit 0
fi

# Export current config
sudo nginx-discover export json --pretty -o "$CURRENT"

# Compare
if diff -q "$BASELINE" "$CURRENT" > /dev/null; then
    echo "✓ No configuration changes detected"
else
    echo "⚠ Configuration has changed!"
    echo
    echo "Changes:"
    diff -u "$BASELINE" "$CURRENT"

    # Update baseline
    cp "$CURRENT" "$BASELINE"
fi
```

### CI/CD Integration

#### GitHub Actions

```yaml
name: Validate NGINX Config

on: [push, pull_request]

jobs:
  validate:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Install NGINX
      run: sudo apt-get update && sudo apt-get install -y nginx

    - name: Install nginx-discover
      run: |
        cargo install --git https://github.com/urwithajit9/nginx-discovery --features cli

    - name: Run health check
      run: sudo nginx-discover doctor

    - name: Generate report
      run: |
        sudo nginx-discover extract servers --format json > servers.json
        sudo nginx-discover extract logs --format json > logs.json

    - name: Upload artifacts
      uses: actions/upload-artifact@v3
      with:
        name: nginx-config-report
        path: |
          servers.json
          logs.json
```

---

## Output Formats

### Table Format (Default)

Beautiful, human-readable tables with borders:

```bash
sudo nginx-discover extract servers
```

Best for: Terminal viewing, quick inspection

### JSON Format

Structured data for programmatic processing:

```bash
sudo nginx-discover extract servers --format json
```

Best for: APIs, automation, jq processing

Example:
```json
[
  {
    "server_names": ["example.com"],
    "listen": [
      {
        "address": "*",
        "port": 80,
        "ssl": false,
        "http2": false,
        "default_server": false
      }
    ],
    "locations": [...]
  }
]
```

### YAML Format

Human-readable structured data:

```bash
sudo nginx-discover extract servers --format yaml
```

Best for: Configuration files, documentation

Example:
```yaml
- server_names:
  - example.com
  listen:
  - address: "*"
    port: 80
    ssl: false
  locations: []
```

### CSV Format

Spreadsheet-compatible format:

```bash
sudo nginx-discover extract servers --format csv > servers.csv
```

Best for: Excel, data analysis, reporting

Example:
```csv
Server Name,Port,SSL,Locations,Default
example.com,80,No,3,No
api.example.com,443,Yes,5,No
```

---

## Tips & Tricks

### 1. Combine with Standard Tools

**Use with jq:**

```bash
# Count servers per port
sudo nginx-discover extract servers --format json | \
    jq 'group_by(.listen[0].port) | map({port: .[0].listen[0].port, count: length})'

# Find servers without SSL
sudo nginx-discover extract servers --format json | \
    jq '.[] | select(.listen[].ssl == false) | .server_names[0]'
```

**Use with grep:**

```bash
# Find all proxy locations
sudo nginx-discover extract locations | grep Proxy

# Count SSL servers
sudo nginx-discover extract servers --ssl-only | grep -c "│"
```

**Use with awk:**

```bash
# Extract just server names and ports
sudo nginx-discover extract servers --format csv | awk -F',' '{print $1, $2}'
```

### 2. Create Aliases

Add to your `.bashrc` or `.zshrc`:

```bash
alias ngx-check='sudo nginx-discover doctor'
alias ngx-servers='sudo nginx-discover extract servers'
alias ngx-logs='sudo nginx-discover extract logs --with-formats'
alias ngx-export='sudo nginx-discover export json --pretty'
```

### 3. Use in Scripts

```bash
#!/bin/bash

# Get server count
SERVER_COUNT=$(sudo nginx-discover extract servers --format json | jq '. | length')

# Get SSL server count
SSL_COUNT=$(sudo nginx-discover extract servers --ssl-only --format json | jq '. | length')

echo "Total servers: $SERVER_COUNT"
echo "SSL servers: $SSL_COUNT"
echo "HTTP-only: $((SERVER_COUNT - SSL_COUNT))"
```

### 4. Configuration Diffing

```bash
# Before changes
sudo nginx-discover export json --pretty > before.json

# Make changes to NGINX config

# After changes
sudo nginx-discover export json --pretty > after.json

# View differences
diff -u before.json after.json
```

### 5. Automated Documentation

```bash
#!/bin/bash
# generate-docs.sh

cat > NGINX_INFRASTRUCTURE.md << 'EOF'
# NGINX Infrastructure Documentation

Auto-generated on $(date)

## Server Summary

$(sudo nginx-discover parse --summary)

## All Servers

$(sudo nginx-discover extract servers --format table)

## Proxy Endpoints

$(sudo nginx-discover extract locations --proxy-only --format table)

## Log Configuration

$(sudo nginx-discover extract logs --with-formats --format table)
EOF

echo "Documentation generated: NGINX_INFRASTRUCTURE.md"
```

---

## Troubleshooting

### Permission Denied

**Problem:**
```
Error: Permission denied reading /etc/nginx/nginx.conf
```

**Solution:**
Run with `sudo`:
```bash
sudo nginx-discover parse
```

### Configuration File Not Found

**Problem:**
```
Error: Could not find NGINX configuration file
```

**Solution:**
Specify the config file path:
```bash
nginx-discover --config /path/to/nginx.conf parse
```

### nginx -t Fails in Doctor

**Problem:**
```
✗ Configuration syntax error: open() "/run/nginx.pid" failed (13: Permission denied)
```

**Explanation:**
This is expected if you're not running as root. The syntax check still validates the configuration structure.

**Solution:**
Run with `sudo`:
```bash
sudo nginx-discover doctor
```

### No Servers Found

**Problem:**
Parsing succeeds but no servers are extracted.

**Possible causes:**
1. Servers are defined in included files
2. Configuration uses unconventional structure

**Solution:**
```bash
# Check if includes are present
sudo nginx-discover parse --tree | grep include

# Manually check included files
sudo nginx-discover --config /etc/nginx/sites-enabled/default parse
```

### Color Output Issues

**Problem:**
Colors don't work or escape codes appear in output.

**Solution:**
```bash
# Force colors
nginx-discover --color always parse

# Disable colors
nginx-discover --color never parse

# Auto-detect (default)
nginx-discover --color auto parse
```

### Large Configuration Files

**Problem:**
Parsing is slow or output is too large.

**Solution:**
Use filters and output to files:
```bash
# Filter by server name
sudo nginx-discover extract servers --name "api.*" --format json -o api-servers.json

# Extract only what you need
sudo nginx-discover extract locations --proxy-only -o proxies.txt
```

---

## Getting Help

### Command Help

```bash
# General help
nginx-discover --help

# Command-specific help
nginx-discover parse --help
nginx-discover extract --help
nginx-discover extract servers --help
```

### Verbose Output

```bash
# See what the tool is doing
nginx-discover --verbose parse
```

### Report Issues

If you encounter a bug:

1. Run with `--verbose`
2. Include the output
3. Report at: https://github.com/urwithajit9/nginx-discovery/issues

### Community

- **GitHub**: https://github.com/urwithajit9/nginx-discovery
- **Documentation**: https://docs.rs/nginx-discovery
- **Crate**: https://crates.io/crates/nginx-discovery

---

## Advanced Usage

### Custom Config Paths

```bash
# Development config
nginx-discover --config ./nginx-dev.conf parse

# Production config
nginx-discover --config /etc/nginx/nginx.conf parse

# Test config
nginx-discover --config /tmp/test.conf doctor
```

### Quiet Mode for Scripts

```bash
#!/bin/bash
set -e

# Only output on error
if ! sudo nginx-discover --quiet doctor; then
    echo "Configuration validation failed!" >&2
    exit 1
fi

# Continue with deployment
echo "Deploying..."
```

### Chaining Commands

```bash
# Export, filter, and count
sudo nginx-discover extract servers --format json | \
    jq '.[] | select(.listen[].ssl == true)' | \
    jq -s '. | length'

# Generate report
{
    echo "# NGINX Configuration Report"
    echo
    sudo nginx-discover parse --summary
    echo
    echo "## Servers"
    sudo nginx-discover extract servers --format table
} > report.txt
```

---

## Appendix

### Feature Matrix

| Feature | Supported | Notes |
|---------|-----------|-------|
| Parse configs || Full support |
| Extract servers || With filtering |
| Extract logs || With formats |
| Extract locations || With filtering |
| SSL analysis || Basic support |
| Health checks || Multiple checks |
| JSON export || Full support |
| YAML export || Full support |
| CSV export || For tables |
| Include resolution || Planned v0.3.0 |
| Upstream extraction || Planned v0.3.0 |
| Security audit || Planned v0.4.0 |

### Performance Tips

- Use filters to reduce output size
- Redirect large outputs to files
- Use `--quiet` in automated scripts
- Consider caching exported configs

### Version History

- **v0.2.1** - CLI implementation, Phase 1 complete
- **v0.2.0** - Server extraction support
- **v0.1.0** - Initial release, log extraction

---

**Need more help?** Check the [main documentation](https://docs.rs/nginx-discovery) or [open an issue](https://github.com/urwithajit9/nginx-discovery/issues).