📜 ⬆️ ⬇️

include mini rake with default virtual host

In connection with the increasing interest in nginx, including in the Linux environment, I want to remind you of one inconspicuous potential rake with virtual hosts and the default host, which is rather painful to attack.

Refer to the documentation for the listen directive :
If the directive has the default parameter, the server in which this directive is described will be the default server for the specified address: port pair. If there are no directives with the default parameter, then the default server will be the first server, which describes the address: port pair

And now let's take a look at the default config that comes in some Linux distributions:
 ... include /etc/nginx/sites-enabled/*; ... 

Nothing suspicious, right? Let's look at the default server configuration, which lies in the default file:
  ...
 listen 80;
 ... 

Also, like, no crime. And now it's time to tell about the rake - the include directive does not guarantee that the included files will be sorted in any particular order, since processing the include directive includes calling ngx_open_glob(...) , which calls glob(pattern, GLOB_NOSORT, ...) - of course, extra sorting is disabled in order not to waste precious time quanta on it. But at the same time, the listen directive does not use the explicit explicit flag, so you can get quite unexpected behavior.

It's great that even in such trifles the server remains faithful to the idea of ​​maximum performance, but be careful - the scalpel is sharp and can suddenly shoot in the foot!

')

Source: https://habr.com/ru/post/50722/


All Articles