Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing beginners_guide description and suggested fix #72

Open
QuantumApprentice opened this issue Sep 14, 2024 · 0 comments
Open

Confusing beginners_guide description and suggested fix #72

QuantumApprentice opened this issue Sep 14, 2024 · 0 comments

Comments

@QuantumApprentice
Copy link

Directives are divided into simple directives and block directives.
A simple directive consists of the name and parameters separated by spaces
and ends with a semicolon (<literal>;</literal>).
A block directive has the same structure as a simple directive, but
instead of the semicolon it ends with a set of additional instructions
surrounded by braces (<literal>{</literal> and <literal>}</literal>).
If a block directive can have other directives inside braces,
it is called a context (examples:
<link doc="ngx_core_module.xml" id="events"/>,
<link doc="http/ngx_http_core_module.xml" id="http"/>,
<link doc="http/ngx_http_core_module.xml" id="server"/>,
and
<link doc="http/ngx_http_core_module.xml" id="location"/>).
</para>

As a new programmer learning to set up nginx, I find two things confusing about how the Beginner's Guide is written:
First, while there's an entire paragraph on the directive syntax, it's somewhat poorly defined.

"A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }). If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location)."

In this explanation no examples are given of either a simple directive, or a block directive, nor are there any code blocks demonstrating them. There are examples of context names, but again no code example.
There are examples in the next section (Serving Static Content), but only the first describes the http and server directives as "blocks", the word "simple" (ie "simple directive") is not used again. So its a bit unclear where to use the "simple directive" syntax on first read.

Second, going by the examples given, a simple directive appears to be a { key : value } pair nested in an object, but this is the first syntax I've run into that uses the space character " " (or whitespace in general) to separate the key and the value (name and parameter?) instead of = or : or something more visible. This is easy to understand after looking at the location entry
http://nginx.org/en/docs/http/ngx_http_core_module.html#location
and scrolling down far enough to see several code examples, but in my humble opinion this part of the syntax could be more easily demonstrated here with some example code.

If it's acceptable, I'd like to suggest these changes:

A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). (examples: root, listen, proxy_pass) *Note the number of spaces doesn't change the assignment
#examples of simple directives
#   name         parameter;
    listen       8080;
    proxy_pass   http://localhost:8080/;
    root         /data;

A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces { and }. (examples: http, server, and location).

  http {                     #block directive
    server {                 #block directive
        location /images/ {  #block directive
            root /data;      #simple directive
        }
    }
  }

If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).

#example of a context
  server {                  #block context
    location / {            #block directive
        root /data/www;     #simple directive
    }

    location /images/ {     #block directive
        root /data;         #simple directive
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant