Nginx directives, arguments and configuration blocks
Read a configuration as instructions for the server
A directive is a named configuration instruction. It tells Nginx how to configure a feature, such as the number of worker processes or the address to listen on. A simple directive has a name, any required arguments and a terminating semicolon. A block directive groups other configuration entries inside braces. Nginx configuration describes behavior; it is not a shell script or a sequence of commands to run for every request.
worker_processes 1;pid logs/nginx.pid;The first directive requests one worker process. The second selects the master process ID file. Both belong at the outermost level. The paths in this chapter refer to the dedicated lab from Chapter 2, not a system service.
Arguments and block boundaries
The braces enclose the settings belonging to events. The inner directive sets a per-worker connection limit, not a promise of 32 simultaneous users. The closing brace does not need a semicolon. Spaces and line breaks make the configuration readable; indentation does not create nesting. A semicolon separates simple directives, even if they are on the same line.
Comments, quotes and escaped characters
location / { # This path contains a space. root "site files";}A hash outside a quoted or escaped token starts a comment through the end of the line. Quotes can keep spaces within a single argument. Here the root value is one path, site files, rather than two arguments. A backslash can protect a character from its normal parsing role, such as a quote inside a quoted string. Exact interpretation also depends on the directive: a regular expression, path and response string need not process the same escaped text identically. Quotes are not a general way to disable Nginx variable expansion.
Both root examples intend a relative directory containing a space. Neither creates that directory; it must already exist within the lab prefix for a file to be served.
Correct a missing semicolon
worker_processes 1pid logs/nginx.pid;Without the first semicolon, Nginx can treat tokens from the second line as extra arguments to the first directive. The diagnostic may therefore point to a later line or report an invalid argument count.
Now the parser can distinguish two directives. A syntactically correct fragment still needs the right surrounding context and a complete configuration. The next lesson explains where directives belong.
Use the dedicated Chapter 3 fixture and reviewed lab binary. A configuration test may open files or load modules; it is not just a harmless text parser.
Practice
Rewrite events { worker_connections 32 } with the missing punctuation. Explain which character terminates the inner directive and which character closes its block. Then compare your result with the staged practice.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Directives and blocks
Check the main concepts taught in this lesson.
What terminates a simple directive?
What makes worker_connections belong inside events?
Why quote a path containing spaces?
What is wrong with `worker_processes 1` followed by `pid logs/nginx.pid;`?
Which part of `# temporary note` is parsed as a directive on its own line?