# Random order of configuration file reading

**URL:** <https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821>\
**Category:** NGINX\
**Created:** [November 27, 2012, 3:08pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821 "2012-11-27T15:08:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 27, 2012, 3:08pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/1 "2012-11-27T15:08:15Z")

</div>

Hello,

we have a bunch of servers which are configured 100% equal expect of  
host  
specific settings like ip address in the listener using chef/puppet.  
Nginx  
seems to read include / config files not in the same order on each  
server.

For example we haven’t defined a default vhost on each server… so  
nginx  
uses the first loaded file which is [exampleA.com](http://exampleA.com) on server 1 and  
[exampleB.com](http://exampleB.com) on server 2.

Furhtermore we use the upstream check status module, the status page is  
randomly ordered at each server…

Is it possible to configure nginx to read config in the alphabeticial  
order?

For example

vhosts/exampleA.com (1.)  
vhosts/exampleB.com (2.)

…

Posted at Nginx Forum:

> **[Random order of configuration file reading](https://forum.nginx.org/read.php?2,233269,233269#msg-233269)**
>
> Hello, we have a bunch of servers which are configured 100% equal expect of host specific settings like ip address in the listener using chef/puppet. Nginx seems to read include / config files not in the same order on each server. For example we...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 12:49pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/2 "2012-11-28T12:49:05Z")

</div>

Hi,

On Tue, Nov 27, 2012 at 10:07 PM, philipp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Furhtermore we use the upstream check status module, the status page is  
> randomly ordered at each server…
> 
> Is it possible to configure nginx to read config in the alphabeticial  
> order?
> 
> For example
> 
> vhosts/exampleA.com (1.)  
> vhosts/exampleB.com (2.)

This is a known issue. It has been fixed in our own  
Tengine[http://tengine.taobao.org](http://tengine.taobao.org)  
distribution:  
[https://github.com/taobao/tengine/blob/master/src/os/unix/ngx\_files.c#L362](https://github.com/taobao/tengine/blob/master/src/os/unix/ngx_files.c#L362)

If you want to use official nginx only, you can apply the patch below:

@Maxim:  
Would you please consider to apply this patch to the trunk? Thanks in  
advance.

# Index: src/os/unix/ngx\_files.c

— src/os/unix/ngx\_files.c (revision 4942)  
+++ src/os/unix/ngx\_files.c (working copy)  
@@ -363,7 +363,7 @@  
{  
int n;

- n = glob((char \*) gl-\>pattern, GLOB\_NOSORT, NULL, &gl-\>pglob);

- n = glob((char \*) gl-\>pattern, 0, NULL, &gl-\>pglob);

Regards,

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 1:23pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/3 "2012-11-28T13:23:35Z")

</div>

Hello!

On Wed, Nov 28, 2012 at 07:48:27PM +0800, Joshua Z. wrote:

> > For example we haven’t defined a default vhost on each server… so nginx
> 
> @Maxim:  
> Would you please consider to apply this patch to the trunk? Thanks in  
> advance.

I’ve already proposed removing GLOB\_NOSORT to Igor a while ago.  
His position on this is to keep this in sync with Windows version  
where there is no sort guaranties.

[…]

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 1:29pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/4 "2012-11-28T13:29:26Z")

</div>

> > Hello!
> 
> > I’ve already proposed removing GLOB\_NOSORT to Igor a while ago.  
> > His position on this is to keep this in sync with Windows version  
> > where there is no sort guaranties.
> > 
> > […]
> 
> Can’t we just pass that as a config option so that the configure script  
> detects the build environment and if were on \*NIX the sorting is enabled?

s/were/we’re/

–appa

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 1:55pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/5 "2012-11-28T13:55:44Z")

</div>

On 28.11.2012 14:23, Maxim D. wrote:

> I’ve already proposed removing GLOB\_NOSORT to Igor a while ago.  
> His position on this is to keep this in sync with Windows version  
> where there is no sort guaranties.

this just can be described in documentation as drawback  
of windows version of nginx, as many other “Known issues”  
and limitations at [nginx for Windows](http://nginx.org/en/docs/windows.html)

because the UNIX version of nginx is the major and main stream.  
so the best possible capabilities must be present in UNIX version,  
not in windows one. and windows version must be compatible with  
UNIX version, if this is possible.

now - capabilities of mainstream UNIX version artificially limited  
to be “compatible” with even not-production-ready windows version.

this is very strange and unexpected and confusing  
for users of mainstream UNIX/Linux version of nginx  
(and this is more than 99% of all use cases of nginx)

for example, windows 7 not support cache module  
and many other modules - but this is not reason  
for remove this feature from UNIX version of nginx.

P.S.

similar example: method java.io.File.renameTo  
(function “rename”)works differently on Windows and UNIX,  
this is “Known issues” and can’t be avoided in any case.

btw, similar “rename bugs” and incompatibilities also  
must be presented also in windows/unix version of nginx

[http://bugs.sun.com/bugdatabase/view\_bug.do?bug\_id=4017593](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4017593)  
java.io.File.renameTo has different semantics on Solaris and Win32

> **[rename](https://pubs.opengroup.org/onlinepubs/009695399/functions/rename.html)**

rename

–  
Best regards,  
Gena

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 1:27pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/6 "2012-11-28T13:27:41Z")

</div>

> Hello!

> I’ve already proposed removing GLOB\_NOSORT to Igor a while ago.  
> His position on this is to keep this in sync with Windows version  
> where there is no sort guaranties.
> 
> […]

Can’t we just pass that as a config option so that the configure script  
detects the build environment and if were on \*NIX the sorting is  
enabled?

Thanks,  
–appa

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2012, 3:16pm UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/7 "2012-11-28T15:16:24Z")

</div>

Hello!

On Wed, Nov 28, 2012 at 01:27:04PM +0100, Antonio P.P. Almeida wrote:

> > Hello!
> 
> > I’ve already proposed removing GLOB\_NOSORT to Igor a while ago.  
> > His position on this is to keep this in sync with Windows version  
> > where there is no sort guaranties.
> > 
> > […]
> 
> Can’t we just pass that as a config option so that the configure script  
> detects the build environment and if were on \*NIX the sorting is enabled?

The codepath in question is unix-only, the question is about user  
experience which will be different on unix and win32 with  
GLOB\_NOSORT removed on unix.

Right now one can’t rely on wildcard include ordering, and this is  
consistent for all platforms supported. And “listen … default”  
should be used to mark default server if one uses wildcard include  
to include multiple server blocks listening on the same some  
ip:port. With the GLOB\_NOSORT removed the behaviour will be  
different on unix (included files will be sorted) and win32  
(included files are not guaranteed to be sorted), which is  
considered bad.

(I personally think that GLOB\_NOSORT should be removed anyway.  
I’ll talk to Igor again about this.)

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 30, 2012, 6:22am UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/8 "2012-11-30T06:22:37Z")

</div>

Hi,

On Fri, Nov 30, 2012 at 7:25 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello!

[…]

> I’ve discussed this with Igor, and this time he finnally approved  
> removing GLOB\_NOSORT. Committed,

Cool! Thanks 🙂

Regards,

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 30, 2012, 12:25am UTC](https://www.ruby-forum.com/t/random-order-of-configuration-file-reading/224821/9 "2012-11-30T00:25:35Z")

</div>

Hello!

On Wed, Nov 28, 2012 at 06:15:50PM +0400, Maxim D. wrote:

> > > […]  
> > > should be used to mark default server if one uses wildcard include  
> > > to include multiple server blocks listening on the same some  
> > > ip:port. With the GLOB\_NOSORT removed the behaviour will be  
> > > different on unix (included files will be sorted) and win32  
> > > (included files are not guaranteed to be sorted), which is  
> > > considered bad.
> 
> (I personally think that GLOB\_NOSORT should be removed anyway.  
> I’ll talk to Igor again about this.)

I’ve discussed this with Igor, and this time he finnally approved  
removing GLOB\_NOSORT. Committed,

[http://trac.nginx.org/nginx/changeset/4944/nginx](http://trac.nginx.org/nginx/changeset/4944/nginx)

Thanks to all for prodding this.

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
