The relationship between Nginx- module configuration instruction block

1. Experimental

A relationship between the following three experiments give you a better understanding

On server1:

vim /usr/local/nginx/conf/nginx.conf 
	server { 
		listen 		80; 
		server_name localhost; 

		location / { 
			root html; 
			index index.html index.htm; 
		} 
		location /demo { 
			root /opt; 
			index index.html index.htm; 
		} 

		error_page 500 502 503 504 /50x.html; 
		location = /50x.html { 
			root html; 
		} 
}

Here Insert Picture Description
Configure Publishing catalog:

mkdir /opt/demo
cd /opt/demo/
vim index.html
nginx -s reload

Here Insert Picture Description

test:
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

The same instructions can also be placed on the stage, it will not affect the results
Here Insert Picture Description
test:
Here Insert Picture Description

Here Insert Picture Description

When the configuration directives EDITORIAL location within the write command, it will cover the outside of the unified command:
Here Insert Picture Description

test:
Here Insert Picture Description

2. The relationship between modules, configuration instructions, block

  • Through the above example, you must understand the truth,When equipped with the same instruction, with the different blocks, the corresponding "scope" are different.
    Some instructions can only be configured with http block, some instructions can only be configured with the location block, but some of the configuration instructions arranged both arranged at http server block in the block, and some instructions can only be disposed in the main configure the area.

    Index just examples of those instructions on both arranged in the location block, but arranged in the server block, the instructions are also assigned at http block, but, when the index instruction arranged in different blocks, corresponding to different scopes.
  • Some instructions in the server block both ligand, can be equipped with at http block,When there is a plurality of identical configuration server, we can use these same http configuration instruction to extract a block, a server to a plurality of blocks share these configurations.
    Of course, if you are in a server in a separate corresponding instructions are configured, then the server will still be subject to its own configuration.
  • In fact, the "configuration directive" and not just "block" There is a certain relationship, "Configuration command" and "module" is also very close correspondence. nginx is modular, different "modules" in charge of different "functions."So, when we need to be configured for a "feature", you need to use the corresponding "configuration instructions." Basically, each "configuration directive" all belong to one "module", a "module" there will be one or more "configuration instructions," when we want to set the relevant functions or modules, on It will be used to configure the instruction corresponding module.

3. How to view official documents

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

Published 175 original articles · won praise 11 · views 6057

Guess you like

Origin blog.csdn.net/weixin_45775963/article/details/104538670