@enjoys/context-engine 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/commands/journalctl.json +203 -66
- package/data/commands/manifest.json +6 -2
- package/data/commands/systemctl.json +800 -23
- package/data/commands/systemd-analyze.json +239 -0
- package/data/commands/zsh.json +166 -0
- package/data/completion/nginx.json +561 -77
- package/data/completion/systemd.json +795 -47
- package/data/completion/zsh.json +829 -70
- package/data/defination/nginx.json +416 -32
- package/data/defination/systemd.json +538 -56
- package/data/defination/zsh.json +323 -86
- package/data/hover/nginx.json +59 -17
- package/data/hover/systemd.json +42 -7
- package/data/hover/zsh.json +44 -9
- package/package.json +2 -2
package/data/defination/zsh.json
CHANGED
|
@@ -2,112 +2,349 @@
|
|
|
2
2
|
"language": "zsh",
|
|
3
3
|
"definitions": {
|
|
4
4
|
"alias": {
|
|
5
|
-
"signature": "alias name=
|
|
6
|
-
"description": "
|
|
7
|
-
"type": "builtin"
|
|
8
|
-
"module": "zsh"
|
|
5
|
+
"signature": "alias [-grs] [name[=value] ...]",
|
|
6
|
+
"description": "Define or display aliases. -g: global alias (expanded anywhere). -r: regular alias. -s: suffix alias (file extension handler).",
|
|
7
|
+
"type": "builtin"
|
|
9
8
|
},
|
|
10
|
-
"
|
|
11
|
-
"signature": "
|
|
12
|
-
"description": "
|
|
13
|
-
"type": "
|
|
14
|
-
|
|
9
|
+
"autoload": {
|
|
10
|
+
"signature": "autoload [-UXz] function ...",
|
|
11
|
+
"description": "Mark function for autoloading from fpath. -U: suppress alias expansion. -z: zsh-style loading. Functions loaded on first call.",
|
|
12
|
+
"type": "builtin"
|
|
13
|
+
},
|
|
14
|
+
"bg": {
|
|
15
|
+
"signature": "bg [job ...]",
|
|
16
|
+
"description": "Resume suspended jobs in background.",
|
|
17
|
+
"type": "builtin"
|
|
18
|
+
},
|
|
19
|
+
"bindkey": {
|
|
20
|
+
"signature": "bindkey [-evaMsR] [key] [widget]",
|
|
21
|
+
"description": "Bind keys to ZLE widgets. -e: emacs keymap. -v: vi keymap. -M: specify keymap. -l: list keymaps.",
|
|
22
|
+
"type": "builtin"
|
|
23
|
+
},
|
|
24
|
+
"builtin": {
|
|
25
|
+
"signature": "builtin name [args]",
|
|
26
|
+
"description": "Execute a builtin command, ignoring functions and aliases with the same name.",
|
|
27
|
+
"type": "builtin"
|
|
28
|
+
},
|
|
29
|
+
"cd": {
|
|
30
|
+
"signature": "cd [-qsLP] [dir | old new]",
|
|
31
|
+
"description": "Change directory. With two args, replaces 'old' with 'new' in $PWD. cd - goes to $OLDPWD.",
|
|
32
|
+
"type": "builtin"
|
|
33
|
+
},
|
|
34
|
+
"compdef": {
|
|
35
|
+
"signature": "compdef function command ...",
|
|
36
|
+
"description": "Associate a completion function with commands. Part of the completion system.",
|
|
37
|
+
"type": "builtin"
|
|
38
|
+
},
|
|
39
|
+
"declare": {
|
|
40
|
+
"signature": "declare [-aAfFgilrtux] [name[=value] ...]",
|
|
41
|
+
"description": "Same as typeset. Declare variables with attributes.",
|
|
42
|
+
"type": "builtin"
|
|
43
|
+
},
|
|
44
|
+
"dirs": {
|
|
45
|
+
"signature": "dirs [-clpv]",
|
|
46
|
+
"description": "Display directory stack. -v: verbose listing with indices. -c: clear stack.",
|
|
47
|
+
"type": "builtin"
|
|
48
|
+
},
|
|
49
|
+
"echo": {
|
|
50
|
+
"signature": "echo [-neE] [string ...]",
|
|
51
|
+
"description": "Print arguments. -n: no trailing newline. -e: interpret escapes. Use print for more control.",
|
|
52
|
+
"type": "builtin"
|
|
53
|
+
},
|
|
54
|
+
"emulate": {
|
|
55
|
+
"signature": "emulate [-lLR] mode",
|
|
56
|
+
"description": "Set shell emulation mode: zsh, sh, ksh, csh. -L: local to function. -R: reset all options.",
|
|
57
|
+
"type": "builtin"
|
|
58
|
+
},
|
|
59
|
+
"eval": {
|
|
60
|
+
"signature": "eval [arg ...]",
|
|
61
|
+
"description": "Concatenate args and execute as a command. Arguments undergo expansion twice.",
|
|
62
|
+
"type": "builtin"
|
|
63
|
+
},
|
|
64
|
+
"exec": {
|
|
65
|
+
"signature": "exec [-cl] [-a name] command [args]",
|
|
66
|
+
"description": "Replace shell with command. With no command, redirections affect current shell.",
|
|
67
|
+
"type": "builtin"
|
|
15
68
|
},
|
|
16
69
|
"export": {
|
|
17
|
-
"signature": "export
|
|
18
|
-
"description": "
|
|
19
|
-
"type": "builtin"
|
|
20
|
-
"module": "zsh"
|
|
70
|
+
"signature": "export [-n] [name[=value] ...]",
|
|
71
|
+
"description": "Mark variables for export to child processes. Same as typeset -gx.",
|
|
72
|
+
"type": "builtin"
|
|
21
73
|
},
|
|
22
|
-
"
|
|
23
|
-
"signature": "
|
|
24
|
-
"description": "
|
|
25
|
-
"type": "builtin"
|
|
26
|
-
|
|
74
|
+
"fc": {
|
|
75
|
+
"signature": "fc [-e editor] [-nlrdDfEim] [first [last]]",
|
|
76
|
+
"description": "Fix command — list, edit, or re-execute history entries.",
|
|
77
|
+
"type": "builtin"
|
|
78
|
+
},
|
|
79
|
+
"fg": {
|
|
80
|
+
"signature": "fg [job ...]",
|
|
81
|
+
"description": "Bring job to foreground.",
|
|
82
|
+
"type": "builtin"
|
|
83
|
+
},
|
|
84
|
+
"float": {
|
|
85
|
+
"signature": "float [-Hg] [-E n] [-F n] [name[=value] ...]",
|
|
86
|
+
"description": "Declare floating-point variables.",
|
|
87
|
+
"type": "builtin"
|
|
88
|
+
},
|
|
89
|
+
"functions": {
|
|
90
|
+
"signature": "functions [-mMtTuUz] [name ...]",
|
|
91
|
+
"description": "Display or set attributes on functions. Same as typeset -f.",
|
|
92
|
+
"type": "builtin"
|
|
93
|
+
},
|
|
94
|
+
"hash": {
|
|
95
|
+
"signature": "hash [-dfmrv] [name[=value] ...]",
|
|
96
|
+
"description": "Manage command hash table. Maps command names to paths for faster lookup.",
|
|
97
|
+
"type": "builtin"
|
|
98
|
+
},
|
|
99
|
+
"integer": {
|
|
100
|
+
"signature": "integer [-i base] [name[=value] ...]",
|
|
101
|
+
"description": "Declare integer variables. Arithmetic is performed on assignments.",
|
|
102
|
+
"type": "builtin"
|
|
103
|
+
},
|
|
104
|
+
"kill": {
|
|
105
|
+
"signature": "kill [-s signal | -n num | -sig] pid|jobspec ...",
|
|
106
|
+
"description": "Send signal to process or job. -l: list signals. -9: SIGKILL.",
|
|
107
|
+
"type": "builtin"
|
|
108
|
+
},
|
|
109
|
+
"let": {
|
|
110
|
+
"signature": "let expr ...",
|
|
111
|
+
"description": "Evaluate arithmetic expression. Same as (( expr )).",
|
|
112
|
+
"type": "builtin"
|
|
113
|
+
},
|
|
114
|
+
"local": {
|
|
115
|
+
"signature": "local [-aAFghilrtux] [name[=value] ...]",
|
|
116
|
+
"description": "Declare local variables in functions. Same as typeset in a function context.",
|
|
117
|
+
"type": "builtin"
|
|
118
|
+
},
|
|
119
|
+
"popd": {
|
|
120
|
+
"signature": "popd [-q] [+n | -n]",
|
|
121
|
+
"description": "Remove directory from stack and cd to new top.",
|
|
122
|
+
"type": "builtin"
|
|
123
|
+
},
|
|
124
|
+
"print": {
|
|
125
|
+
"signature": "print [-abcDilmnNoOpPrsz] [-u fd] [-f fmt] [args ...]",
|
|
126
|
+
"description": "Print arguments. More powerful than echo. -P: prompt expansion. -f: printf format. -l: one per line.",
|
|
127
|
+
"type": "builtin"
|
|
128
|
+
},
|
|
129
|
+
"printf": {
|
|
130
|
+
"signature": "printf format [args ...]",
|
|
131
|
+
"description": "Formatted output. Supports %s (string), %d (decimal), %f (float), %x (hex), etc.",
|
|
132
|
+
"type": "builtin"
|
|
133
|
+
},
|
|
134
|
+
"pushd": {
|
|
135
|
+
"signature": "pushd [-q] [dir | +n | -n]",
|
|
136
|
+
"description": "Push directory onto stack and cd to it.",
|
|
137
|
+
"type": "builtin"
|
|
138
|
+
},
|
|
139
|
+
"read": {
|
|
140
|
+
"signature": "read [-rszpqAce] [-k num] [-d delim] [-t timeout] [name ...]",
|
|
141
|
+
"description": "Read a line of input. -r: raw (no backslash). -s: silent. -t: timeout. -A: into array. -k n: read n chars.",
|
|
142
|
+
"type": "builtin"
|
|
143
|
+
},
|
|
144
|
+
"readonly": {
|
|
145
|
+
"signature": "readonly [-aAf] [name[=value] ...]",
|
|
146
|
+
"description": "Mark variables as read-only. Cannot be changed or unset.",
|
|
147
|
+
"type": "builtin"
|
|
148
|
+
},
|
|
149
|
+
"rehash": {
|
|
150
|
+
"signature": "rehash",
|
|
151
|
+
"description": "Rebuild command hash table. Run after installing new programs.",
|
|
152
|
+
"type": "builtin"
|
|
153
|
+
},
|
|
154
|
+
"return": {
|
|
155
|
+
"signature": "return [n]",
|
|
156
|
+
"description": "Return from a function with exit status n (default: status of last command).",
|
|
157
|
+
"type": "builtin"
|
|
158
|
+
},
|
|
159
|
+
"set": {
|
|
160
|
+
"signature": "set [-+options] [-A name] [args ...]",
|
|
161
|
+
"description": "Set shell options and positional parameters. -e: exit on error. -u: error on unset.",
|
|
162
|
+
"type": "builtin"
|
|
27
163
|
},
|
|
28
164
|
"setopt": {
|
|
29
|
-
"signature": "setopt
|
|
30
|
-
"description": "Enable
|
|
31
|
-
"type": "builtin"
|
|
32
|
-
"module": "zsh"
|
|
165
|
+
"signature": "setopt [option ...]",
|
|
166
|
+
"description": "Enable shell options. Options control shell behavior: globbing, history, cd, correction, etc.",
|
|
167
|
+
"type": "builtin"
|
|
33
168
|
},
|
|
34
|
-
"
|
|
35
|
-
"signature": "
|
|
36
|
-
"description": "
|
|
37
|
-
"type": "builtin"
|
|
38
|
-
"module": "zsh"
|
|
169
|
+
"shift": {
|
|
170
|
+
"signature": "shift [n]",
|
|
171
|
+
"description": "Shift positional parameters left by n (default: 1).",
|
|
172
|
+
"type": "builtin"
|
|
39
173
|
},
|
|
40
|
-
"
|
|
41
|
-
"signature": "
|
|
42
|
-
"description": "
|
|
43
|
-
"type": "builtin"
|
|
44
|
-
"module": "zsh"
|
|
174
|
+
"source": {
|
|
175
|
+
"signature": "source file [args]",
|
|
176
|
+
"description": "Read and execute commands from file in current shell. Same as '.' command.",
|
|
177
|
+
"type": "builtin"
|
|
45
178
|
},
|
|
46
|
-
"
|
|
47
|
-
"signature": "
|
|
48
|
-
"description": "
|
|
49
|
-
"type": "builtin"
|
|
50
|
-
"module": "zsh"
|
|
179
|
+
"test": {
|
|
180
|
+
"signature": "test expression / [ expression ]",
|
|
181
|
+
"description": "Evaluate conditional expression. Prefer [[ ]] for advanced features.",
|
|
182
|
+
"type": "builtin"
|
|
51
183
|
},
|
|
52
|
-
"
|
|
53
|
-
"signature": "
|
|
54
|
-
"description": "
|
|
55
|
-
"type": "builtin"
|
|
56
|
-
|
|
184
|
+
"trap": {
|
|
185
|
+
"signature": "trap [action] [signal ...]",
|
|
186
|
+
"description": "Execute action when shell receives signal. Common: EXIT, INT, TERM, ERR, DEBUG.",
|
|
187
|
+
"type": "builtin"
|
|
188
|
+
},
|
|
189
|
+
"type": {
|
|
190
|
+
"signature": "type [-afmsw] name ...",
|
|
191
|
+
"description": "Show how a name would be interpreted: alias, function, builtin, command.",
|
|
192
|
+
"type": "builtin"
|
|
193
|
+
},
|
|
194
|
+
"typeset": {
|
|
195
|
+
"signature": "typeset [-aAfFghilrtuxmHLRZE] [name[=value] ...]",
|
|
196
|
+
"description": "Declare and set attributes on variables. The most versatile variable declaration command.",
|
|
197
|
+
"type": "builtin"
|
|
198
|
+
},
|
|
199
|
+
"umask": {
|
|
200
|
+
"signature": "umask [-S] [mask]",
|
|
201
|
+
"description": "Get or set file creation mask.",
|
|
202
|
+
"type": "builtin"
|
|
203
|
+
},
|
|
204
|
+
"unalias": {
|
|
205
|
+
"signature": "unalias [-ms] name ...",
|
|
206
|
+
"description": "Remove alias definitions.",
|
|
207
|
+
"type": "builtin"
|
|
208
|
+
},
|
|
209
|
+
"unfunction": {
|
|
210
|
+
"signature": "unfunction name ...",
|
|
211
|
+
"description": "Remove function definitions.",
|
|
212
|
+
"type": "builtin"
|
|
213
|
+
},
|
|
214
|
+
"unset": {
|
|
215
|
+
"signature": "unset [-fmv] name ...",
|
|
216
|
+
"description": "Unset variables or functions.",
|
|
217
|
+
"type": "builtin"
|
|
218
|
+
},
|
|
219
|
+
"unsetopt": {
|
|
220
|
+
"signature": "unsetopt [option ...]",
|
|
221
|
+
"description": "Disable shell options.",
|
|
222
|
+
"type": "builtin"
|
|
223
|
+
},
|
|
224
|
+
"wait": {
|
|
225
|
+
"signature": "wait [job|pid ...]",
|
|
226
|
+
"description": "Wait for background jobs/processes to complete.",
|
|
227
|
+
"type": "builtin"
|
|
228
|
+
},
|
|
229
|
+
"whence": {
|
|
230
|
+
"signature": "whence [-acfmpsvw] name ...",
|
|
231
|
+
"description": "Show how each name would be interpreted. -p: search path only. -v: verbose.",
|
|
232
|
+
"type": "builtin"
|
|
233
|
+
},
|
|
234
|
+
"where": {
|
|
235
|
+
"signature": "where name ...",
|
|
236
|
+
"description": "Display all locations of a command.",
|
|
237
|
+
"type": "builtin"
|
|
238
|
+
},
|
|
239
|
+
"which": {
|
|
240
|
+
"signature": "which [-aps] name ...",
|
|
241
|
+
"description": "Show full path of command.",
|
|
242
|
+
"type": "builtin"
|
|
243
|
+
},
|
|
244
|
+
"zcompile": {
|
|
245
|
+
"signature": "zcompile [-cz] [-R|-M] file [name ...]",
|
|
246
|
+
"description": "Compile zsh scripts to wordcode for faster loading.",
|
|
247
|
+
"type": "builtin"
|
|
248
|
+
},
|
|
249
|
+
"zle": {
|
|
250
|
+
"signature": "zle [-aAcCDFgGIKlLmNRU] [widget]",
|
|
251
|
+
"description": "Zsh Line Editor — manage widgets. -N: create widget from function. -C: create completion widget.",
|
|
252
|
+
"type": "builtin"
|
|
253
|
+
},
|
|
254
|
+
"zmodload": {
|
|
255
|
+
"signature": "zmodload [-diLu] [module ...]",
|
|
256
|
+
"description": "Load or unload zsh modules. Common: zsh/datetime, zsh/stat, zsh/regex, zsh/net/tcp.",
|
|
257
|
+
"type": "builtin"
|
|
258
|
+
},
|
|
259
|
+
"zparseopts": {
|
|
260
|
+
"signature": "zparseopts [-DEKA] specs ...",
|
|
261
|
+
"description": "Parse command-line options. -D: remove parsed options. -E: don't stop at first non-option. -A assoc: store in associative array.",
|
|
262
|
+
"type": "builtin"
|
|
263
|
+
},
|
|
264
|
+
"zstyle": {
|
|
265
|
+
"signature": "zstyle pattern style value ...",
|
|
266
|
+
"description": "Define styles for the completion system and other subsystems. Pattern: ':completion:function:completer:command:argument:tag'.",
|
|
267
|
+
"type": "builtin"
|
|
57
268
|
},
|
|
58
269
|
"PROMPT": {
|
|
59
|
-
"signature": "PROMPT=
|
|
60
|
-
"description": "
|
|
61
|
-
"type": "variable"
|
|
62
|
-
"module": "zsh"
|
|
270
|
+
"signature": "PROMPT=string",
|
|
271
|
+
"description": "Primary prompt string. Supports: %n (user), %m (host), %~ (dir), %F{color}...%f (color), %B...%b (bold), %# (# for root, %% for user).",
|
|
272
|
+
"type": "variable"
|
|
63
273
|
},
|
|
64
274
|
"RPROMPT": {
|
|
65
|
-
"signature": "RPROMPT=
|
|
66
|
-
"description": "Right-side prompt.
|
|
67
|
-
"type": "variable"
|
|
68
|
-
|
|
275
|
+
"signature": "RPROMPT=string",
|
|
276
|
+
"description": "Right-side prompt string. Commonly shows time, git status, or exit code.",
|
|
277
|
+
"type": "variable"
|
|
278
|
+
},
|
|
279
|
+
"PS1": {
|
|
280
|
+
"signature": "PS1=string",
|
|
281
|
+
"description": "Same as PROMPT. Primary prompt.",
|
|
282
|
+
"type": "variable"
|
|
283
|
+
},
|
|
284
|
+
"PS2": {
|
|
285
|
+
"signature": "PS2=string",
|
|
286
|
+
"description": "Continuation prompt (shown for multi-line commands). Default: '%_> '.",
|
|
287
|
+
"type": "variable"
|
|
69
288
|
},
|
|
70
289
|
"HISTFILE": {
|
|
71
|
-
"signature": "HISTFILE
|
|
72
|
-
"description": "
|
|
73
|
-
"type": "variable"
|
|
74
|
-
"module": "zsh"
|
|
290
|
+
"signature": "HISTFILE=path",
|
|
291
|
+
"description": "Path to the history file. Default: ~/.zsh_history.",
|
|
292
|
+
"type": "variable"
|
|
75
293
|
},
|
|
76
294
|
"HISTSIZE": {
|
|
77
|
-
"signature": "HISTSIZE=
|
|
78
|
-
"description": "Maximum number of history entries
|
|
79
|
-
"type": "variable"
|
|
80
|
-
"module": "zsh"
|
|
295
|
+
"signature": "HISTSIZE=number",
|
|
296
|
+
"description": "Maximum number of history entries in memory.",
|
|
297
|
+
"type": "variable"
|
|
81
298
|
},
|
|
82
299
|
"SAVEHIST": {
|
|
83
|
-
"signature": "SAVEHIST=
|
|
84
|
-
"description": "
|
|
85
|
-
"type": "variable"
|
|
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
|
-
"
|
|
300
|
+
"signature": "SAVEHIST=number",
|
|
301
|
+
"description": "Number of history entries saved to HISTFILE.",
|
|
302
|
+
"type": "variable"
|
|
303
|
+
},
|
|
304
|
+
"FPATH": {
|
|
305
|
+
"signature": "FPATH=dirs",
|
|
306
|
+
"description": "Function search path (colon-separated). Directories where autoloaded functions are found.",
|
|
307
|
+
"type": "variable"
|
|
308
|
+
},
|
|
309
|
+
"fpath": {
|
|
310
|
+
"signature": "fpath=(dirs)",
|
|
311
|
+
"description": "Array form of FPATH. Tied to FPATH — changes to one affect the other.",
|
|
312
|
+
"type": "variable"
|
|
313
|
+
},
|
|
314
|
+
"PATH": {
|
|
315
|
+
"signature": "PATH=dirs",
|
|
316
|
+
"description": "Command search path (colon-separated).",
|
|
317
|
+
"type": "variable"
|
|
318
|
+
},
|
|
319
|
+
"path": {
|
|
320
|
+
"signature": "path=(dirs)",
|
|
321
|
+
"description": "Array form of PATH. Tied to PATH.",
|
|
322
|
+
"type": "variable"
|
|
323
|
+
},
|
|
324
|
+
"CDPATH": {
|
|
325
|
+
"signature": "CDPATH=dirs",
|
|
326
|
+
"description": "Directories searched by cd. cd target tries CDPATH entries as parents.",
|
|
327
|
+
"type": "variable"
|
|
328
|
+
},
|
|
329
|
+
"KEYTIMEOUT": {
|
|
330
|
+
"signature": "KEYTIMEOUT=n",
|
|
331
|
+
"description": "Timeout for key sequences (1/100th second). Default: 40 (0.4s). Set to 1 for fast vi-mode switch.",
|
|
332
|
+
"type": "variable"
|
|
333
|
+
},
|
|
334
|
+
"WORDCHARS": {
|
|
335
|
+
"signature": "WORDCHARS=chars",
|
|
336
|
+
"description": "Characters considered part of a word for word-based operations. Default includes many special chars.",
|
|
337
|
+
"type": "variable"
|
|
338
|
+
},
|
|
339
|
+
"ZSH_VERSION": {
|
|
340
|
+
"signature": "ZSH_VERSION",
|
|
341
|
+
"description": "Current zsh version string.",
|
|
342
|
+
"type": "variable"
|
|
343
|
+
},
|
|
344
|
+
"TERM": {
|
|
345
|
+
"signature": "TERM=string",
|
|
346
|
+
"description": "Terminal type for terminfo lookups.",
|
|
347
|
+
"type": "variable"
|
|
111
348
|
}
|
|
112
349
|
}
|
|
113
350
|
}
|
package/data/hover/nginx.json
CHANGED
|
@@ -4,84 +4,126 @@
|
|
|
4
4
|
"server": {
|
|
5
5
|
"contents": [
|
|
6
6
|
{
|
|
7
|
-
"value": "```nginx\nserver {\n listen 80;\n server_name example.com;\n root /var/www/html;\n}\n```\n**server** block defines a virtual host.
|
|
7
|
+
"value": "```nginx\nserver {\n listen 80;\n listen [::]:80;\n server_name example.com www.example.com;\n\n root /var/www/example.com/html;\n index index.html index.htm;\n\n location / {\n try_files $uri $uri/ =404;\n }\n}\n```\n**server** block defines a virtual host. Nginx selects the server based on `listen` address/port and `server_name`. Use `default_server` for fallback."
|
|
8
8
|
}
|
|
9
9
|
]
|
|
10
10
|
},
|
|
11
11
|
"location": {
|
|
12
12
|
"contents": [
|
|
13
13
|
{
|
|
14
|
-
"value": "```nginx\nlocation / {
|
|
14
|
+
"value": "```nginx\n# Priority order (highest to lowest):\nlocation = /exact { } # 1. Exact match\nlocation ^~ /images/ { } # 2. Prefix priority (no regex check)\nlocation ~ \\.php$ { } # 3. Regex (case-sensitive)\nlocation ~* \\.(jpg|png)$ { } # 4. Regex (case-insensitive)\nlocation /prefix { } # 5. Prefix match (longest wins)\nlocation / { } # 6. Default prefix\n```\n**location** matches request URIs. Nginx first checks exact (`=`), then prefix matches (longest wins), then regex (first match wins). `^~` stops regex checking."
|
|
15
15
|
}
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
"upstream": {
|
|
19
19
|
"contents": [
|
|
20
20
|
{
|
|
21
|
-
"value": "```nginx\nupstream backend {\n server 10.0.0.1:8080
|
|
21
|
+
"value": "```nginx\nupstream backend {\n least_conn; # or ip_hash; or hash $uri;\n server 10.0.0.1:8080 weight=3; # 3x traffic\n server 10.0.0.2:8080; # default weight=1\n server 10.0.0.3:8080 backup; # only when others fail\n server 10.0.0.4:8080 down; # marked offline\n server 10.0.0.5:8080 max_fails=3 fail_timeout=30s;\n\n keepalive 32; # connection pool to backends\n}\n```\n**upstream** defines load-balanced backends. Methods: `round-robin` (default), `least_conn`, `ip_hash` (sticky), `hash` (custom key). `weight` controls distribution."
|
|
22
22
|
}
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"listen": {
|
|
26
26
|
"contents": [
|
|
27
27
|
{
|
|
28
|
-
"value": "```nginx\nlisten 80
|
|
28
|
+
"value": "```nginx\nlisten 80; # IPv4 port 80\nlisten [::]:80; # IPv6 port 80\nlisten 443 ssl http2; # HTTPS with HTTP/2\nlisten 8080 default_server; # default for this port\nlisten unix:/var/run/nginx.sock; # Unix socket\nlisten 80 reuseport; # kernel load balancing\nlisten 127.0.0.1:8080; # localhost only\n```\n**listen** sets address, port, and options. Use both IPv4 and IPv6 (`[::]:80`) for dual-stack. `default_server` catches unmatched requests."
|
|
29
29
|
}
|
|
30
30
|
]
|
|
31
31
|
},
|
|
32
32
|
"proxy_pass": {
|
|
33
33
|
"contents": [
|
|
34
34
|
{
|
|
35
|
-
"value": "```nginx\nlocation /api {\n proxy_pass http://backend:3000;\n}\n```\n**proxy_pass** forwards requests to
|
|
35
|
+
"value": "```nginx\n# Simple proxy:\nlocation /api/ {\n proxy_pass http://backend:3000; # keeps /api/ prefix\n}\n\n# Strip prefix:\nlocation /api/ {\n proxy_pass http://backend:3000/; # trailing / strips /api/\n}\n\n# To upstream group:\nlocation / {\n proxy_pass http://my_upstream;\n}\n\n# Essential headers:\nproxy_set_header Host $host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\nproxy_set_header X-Forwarded-Proto $scheme;\n```\n**proxy_pass** forwards requests to backend servers. Trailing `/` in URL controls whether the location prefix is stripped. Always set forwarding headers."
|
|
36
36
|
}
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
|
-
"
|
|
39
|
+
"ssl": {
|
|
40
40
|
"contents": [
|
|
41
41
|
{
|
|
42
|
-
"value": "```nginx\nssl_certificate
|
|
42
|
+
"value": "```nginx\n# Modern SSL configuration (A+ rating):\nssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;\nssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;\n\nssl_protocols TLSv1.2 TLSv1.3;\nssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;\nssl_prefer_server_ciphers off;\n\nssl_session_cache shared:SSL:10m;\nssl_session_timeout 1d;\nssl_session_tickets off;\n\nssl_stapling on;\nssl_stapling_verify on;\n```\n**SSL/TLS** configuration. Use Let's Encrypt with `certbot --nginx`. Test with `ssllabs.com`. Only enable TLSv1.2+ for modern security."
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"try_files": {
|
|
47
47
|
"contents": [
|
|
48
48
|
{
|
|
49
|
-
"value": "```nginx\nlocation / {\n try_files $uri $uri/ /index.html;\n}\n```\n**try_files** checks
|
|
49
|
+
"value": "```nginx\n# Static site:\nlocation / {\n try_files $uri $uri/ =404;\n}\n\n# SPA (React/Vue/Angular):\nlocation / {\n try_files $uri $uri/ /index.html;\n}\n\n# PHP (Laravel/WordPress):\nlocation / {\n try_files $uri $uri/ /index.php?$query_string;\n}\n\n# Named location fallback:\nlocation / {\n try_files $uri @backend;\n}\nlocation @backend {\n proxy_pass http://app:3000;\n}\n```\n**try_files** checks file existence in order. The last argument is the fallback (URI or error code). Essential for SPA routing and PHP frameworks."
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"gzip": {
|
|
54
|
+
"contents": [
|
|
55
|
+
{
|
|
56
|
+
"value": "```nginx\ngzip on;\ngzip_vary on;\ngzip_proxied any;\ngzip_comp_level 6;\ngzip_min_length 256;\ngzip_types\n text/plain\n text/css\n text/javascript\n application/javascript\n application/json\n application/xml\n image/svg+xml\n font/woff2;\n```\n**gzip** compression reduces response size by 60-80%. Level 4-6 is the sweet spot. Don't compress images (already compressed) or responses under 256 bytes. `gzip_vary` is essential for CDN caching."
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"rate_limiting": {
|
|
61
|
+
"contents": [
|
|
62
|
+
{
|
|
63
|
+
"value": "```nginx\n# Define zone in http block:\nlimit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;\nlimit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;\n\n# Apply in location:\nlocation /api/ {\n limit_req zone=api burst=20 nodelay;\n limit_req_status 429;\n}\n\nlocation /login {\n limit_req zone=login burst=5;\n}\n```\n**Rate limiting** uses leaky bucket algorithm. `rate=10r/s` allows 10 req/sec. `burst=20` buffers 20 extra. `nodelay` processes burst immediately instead of queuing."
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"security_headers": {
|
|
68
|
+
"contents": [
|
|
69
|
+
{
|
|
70
|
+
"value": "```nginx\n# Prevent clickjacking:\nadd_header X-Frame-Options \"SAMEORIGIN\" always;\n\n# Prevent MIME sniffing:\nadd_header X-Content-Type-Options \"nosniff\" always;\n\n# Force HTTPS:\nadd_header Strict-Transport-Security \"max-age=63072000; includeSubDomains; preload\" always;\n\n# Content Security Policy:\nadd_header Content-Security-Policy \"default-src 'self'\" always;\n\n# Referrer policy:\nadd_header Referrer-Policy \"strict-origin-when-cross-origin\" always;\n\n# Permissions policy:\nadd_header Permissions-Policy \"camera=(), microphone=()\" always;\n```\n**Security headers** protect against common web attacks. Use `always` to send on error pages too. Test at securityheaders.com."
|
|
50
71
|
}
|
|
51
72
|
]
|
|
52
73
|
},
|
|
53
74
|
"rewrite": {
|
|
54
75
|
"contents": [
|
|
55
76
|
{
|
|
56
|
-
"value": "```nginx\nrewrite ^/
|
|
77
|
+
"value": "```nginx\n# Permanent redirect (301):\nrewrite ^/old/(.*)$ /new/$1 permanent;\n\n# Temporary redirect (302):\nrewrite ^/temp/(.*)$ /alt/$1 redirect;\n\n# Internal rewrite (invisible to client):\nrewrite ^/api/v1/(.*)$ /api/v2/$1 last;\n\n# Stop processing:\nrewrite ^/done/(.*)$ /$1 break;\n\n# Prefer return for simple redirects:\nreturn 301 https://$host$request_uri;\n```\n**rewrite** transforms URIs with regex. `last` restarts location matching. `break` stops rewrite processing. For simple redirects, `return` is faster than `rewrite`."
|
|
57
78
|
}
|
|
58
79
|
]
|
|
59
80
|
},
|
|
60
|
-
"
|
|
81
|
+
"websocket": {
|
|
82
|
+
"contents": [
|
|
83
|
+
{
|
|
84
|
+
"value": "```nginx\nlocation /ws/ {\n proxy_pass http://backend:8080;\n proxy_http_version 1.1;\n proxy_set_header Upgrade $http_upgrade;\n proxy_set_header Connection \"upgrade\";\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n\n # Long timeouts for persistent connections:\n proxy_read_timeout 86400s;\n proxy_send_timeout 86400s;\n}\n```\n**WebSocket** proxying requires HTTP/1.1, Upgrade and Connection headers. Set long timeouts (86400s = 24h) to prevent idle disconnection."
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
"map": {
|
|
89
|
+
"contents": [
|
|
90
|
+
{
|
|
91
|
+
"value": "```nginx\n# Map User-Agent to mobile flag:\nmap $http_user_agent $is_mobile {\n default 0;\n ~*mobile 1;\n ~*android 1;\n ~*iphone 1;\n}\n\n# Map URI to backend:\nmap $uri $backend {\n default http://app:3000;\n ~^/api/ http://api:8080;\n ~^/admin/ http://admin:9090;\n}\n\n# Use in config:\nif ($is_mobile) {\n rewrite ^ /mobile$uri last;\n}\n```\n**map** creates variables based on other variables. Evaluated lazily (only when used). More efficient than multiple if statements."
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"fastcgi": {
|
|
96
|
+
"contents": [
|
|
97
|
+
{
|
|
98
|
+
"value": "```nginx\n# PHP-FPM via Unix socket (recommended):\nlocation ~ \\.php$ {\n include fastcgi_params;\n fastcgi_pass unix:/run/php/php8.2-fpm.sock;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n fastcgi_index index.php;\n fastcgi_intercept_errors on;\n fastcgi_buffer_size 16k;\n fastcgi_buffers 4 16k;\n}\n\n# PHP-FPM via TCP (for separate server):\nlocation ~ \\.php$ {\n fastcgi_pass 10.0.0.5:9000;\n # ...\n}\n```\n**FastCGI** connects nginx to PHP-FPM, Python (via flup), or other FastCGI apps. Unix sockets are faster for same-server setups. TCP for remote."
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"logging": {
|
|
61
103
|
"contents": [
|
|
62
104
|
{
|
|
63
|
-
"value": "```nginx\
|
|
105
|
+
"value": "```nginx\n# Standard combined log:\naccess_log /var/log/nginx/access.log;\n\n# JSON log for ELK/Grafana:\nlog_format json escape=json\n '{\"time\":\"$time_iso8601\",'\n '\"ip\":\"$remote_addr\",'\n '\"method\":\"$request_method\",'\n '\"uri\":\"$uri\",'\n '\"status\":$status,'\n '\"size\":$body_bytes_sent,'\n '\"time_ms\":$request_time,'\n '\"upstream_ms\":\"$upstream_response_time\"}';\naccess_log /var/log/nginx/access.json json;\n\n# Conditional logging (skip health checks):\nmap $uri $loggable {\n /health 0;\n default 1;\n}\naccess_log /var/log/nginx/access.log combined if=$loggable;\n\n# Disable for static assets:\nlocation ~* \\.(css|js|png|jpg)$ {\n access_log off;\n}\n```\n**Logging** - JSON format integrates with ELK/Grafana Loki. Use conditional logging to reduce noise. `$request_time` measures total request processing time."
|
|
64
106
|
}
|
|
65
107
|
]
|
|
66
108
|
},
|
|
67
|
-
"
|
|
109
|
+
"variables": {
|
|
68
110
|
"contents": [
|
|
69
111
|
{
|
|
70
|
-
"value": "```nginx\
|
|
112
|
+
"value": "```nginx\n# Request variables:\n$host # Host header (or server_name)\n$uri # Current URI (after rewrites)\n$request_uri # Original URI with query string\n$args # Query string\n$request_method # GET, POST, etc.\n$scheme # http or https\n$server_port # Port number\n\n# Client variables:\n$remote_addr # Client IP\n$binary_remote_addr # Client IP (binary, for zones)\n$http_user_agent # User-Agent header\n$http_referer # Referer header\n$http_cookie # Cookie header\n$http_<header> # Any request header\n\n# Proxy variables:\n$proxy_add_x_forwarded_for # X-Forwarded-For chain\n$upstream_cache_status # HIT, MISS, etc.\n$upstream_response_time # Backend response time\n```\n**Variables** are available in most directives. `$http_*` accesses any request header. Variables are evaluated lazily."
|
|
71
113
|
}
|
|
72
114
|
]
|
|
73
115
|
},
|
|
74
|
-
"
|
|
116
|
+
"performance": {
|
|
75
117
|
"contents": [
|
|
76
118
|
{
|
|
77
|
-
"value": "```nginx\
|
|
119
|
+
"value": "```nginx\n# Worker tuning:\nworker_processes auto; # = CPU cores\nworker_rlimit_nofile 65535; # max open files per worker\n\nevents {\n worker_connections 4096; # connections per worker\n multi_accept on; # accept all new connections\n use epoll; # Linux: epoll, FreeBSD: kqueue\n}\n\n# TCP optimization:\nsendfile on; # zero-copy file serving\ntcp_nopush on; # combine headers + data\ntcp_nodelay on; # disable Nagle's algorithm\n\n# Keepalive:\nkeepalive_timeout 65;\nkeepalive_requests 1000;\n\n# Buffer sizes:\nclient_body_buffer_size 16k;\nclient_header_buffer_size 1k;\nlarge_client_header_buffers 4 16k;\n\n# File caching:\nopen_file_cache max=1000 inactive=20s;\nopen_file_cache_valid 30s;\nopen_file_cache_min_uses 2;\n```\n**Performance tuning** - match workers to CPUs, tune connections to expected load, enable sendfile for static content. Monitor with `stub_status` module."
|
|
78
120
|
}
|
|
79
121
|
]
|
|
80
122
|
},
|
|
81
|
-
"
|
|
123
|
+
"stub_status": {
|
|
82
124
|
"contents": [
|
|
83
125
|
{
|
|
84
|
-
"value": "```nginx\
|
|
126
|
+
"value": "```nginx\n# Enable status page (restrict access!):\nlocation /nginx_status {\n stub_status on;\n allow 127.0.0.1;\n allow 10.0.0.0/8;\n deny all;\n}\n\n# Output:\n# Active connections: 291\n# server accepts handled requests\n# 16630948 16630948 31070465\n# Reading: 6 Writing: 179 Waiting: 106\n```\n**stub_status** provides basic metrics. Active connections = reading + writing + waiting. Use for monitoring with Prometheus (via nginx-exporter) or Datadog."
|
|
85
127
|
}
|
|
86
128
|
]
|
|
87
129
|
}
|