Opened 9 years ago
Closed 9 years ago
#900 closed defect (fixed)
Nginx won't daemonise if "NGINX" environment variable is set
Reported by: | davidjb | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | documentation | Version: | 1.9.x |
Keywords: | Cc: | ||
uname -a: | Linux localhost.localdomain 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux | ||
nginx -V: |
nginx version: nginx/1.9.11
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) configure arguments: --with-debug |
Description
On non-Win32 platforms, I've found that Nginx won't daemonise if an environment variable with the name NGINX
(any value) is present in the parent environment.
I had written the following:
export NGINX=1.9.11 wget -O - http://nginx.org/download/nginx-${NGINX}.tar.gz | tar -xzf - cd nginx-${NGINX} ./configure --with-debug && make && make install nginx -c ~/nginx.conf -p ~
and discovered that the final command wouldn't daemonise Nginx, even though daemon on
was explicitly present in the configuration. After trial-and-error, I found the cause was the environment variable and I had to consult Nginx's source to discover why this was happening. Nginx believes it is working to inherit sockets (https://github.com/nginx/nginx/blob/master/src/core/nginx.c#L444), which, after the NGINX
variable is read from the environment, flags ngx_inherited = 1
. The invocation for daemonising is at https://github.com/nginx/nginx/blob/master/src/core/nginx.c#L332, which checks for ngx_inherited
and then thus skips over daemonising.
I now know the errors logs *do* output a logging message about this:
2016/02/12 06:52:17 [notice] 8624#0: using inherited sockets from "1.9.11"
but as I had debugging messages enabled, this non-error wasn't obvious amongst the other logged messages.
So, to avoid this pitfall, can the environment variable be made more specific (such as __NGINX_INHERITED_SOCKETS
)? Perhaps an error could also be raised/logged if value supplied to the environment variable are incorrectly formatted, and this behaviour be documented so others avoid this same pitfall.
Change History (3)
comment:1 by , 9 years ago
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
The patch to improve logging committed, thanks for the report.
The NGINX environment variable is explicitly documented in nginx(8) manual page:
There is no error in your case as "1.9.11" doesn't contain ";" or ":", so nginx doesn't try to parse anything from the variable. The following patch should improve logging in such cases:
It can cause unexpected logging during upgrade from versions prior to 0.1.5, but it's probably not something we care about.
Note well that changing the variable name is not really an option, as it should be known to both old and new nginx versions for upgrade to work.