Package: nginx
Version: 1.6.2-5
Severity: normal

Dear Maintainer,

I have the following in my nginx configuration:

   server {
           listen mylocalserver:80;
           server_name mylocalserver;
           # ...
   }

and the following line in /etc/hosts:

   127.0.1.2      mylocalserver

When nginx is started during boot it fails and the following appears
in the log:

Dec 11 14:25:25 steelpick nginx[1800]: nginx: [emerg] host not found in 
"mylocalserver:80" of the "listen" directive in 
/etc/nginx/sites-enabled/mylocalserver:2
Dec 11 14:25:25 steelpick nginx[1800]: nginx: configuration file 
/etc/nginx/nginx.conf test failed

When I start nginx manually (systemctl start nginx.service) after
logging in, it starts correctly. I would like nginx to start correctly
even during boot.

I tried to debug the problem a bit and the following is what I found.

I verified that nginx is started after networking.service, that
loopback interface is up and that `getent hosts mylocalserver` prints
the correct address when executed before nginx is started.

I also compared the strace output of the failed command

    /usr/bin/strace /usr/sbin/nginx -t -q -g 'daemon on; master_process on;

The difference between strace of failed nginx invocation during boot
and manual invocation via systemctl is that during manual invocation
/etc/gai.conf is consulted, whereas during boot, it is not.

    diff --git a/nginx.strace.fail.txt b/nginx.strace.ok.txt
    index 9242fa7..1b0a561 100644
    --- a/nginx.strace.fail.txt
    +++ b/nginx.strace.ok.txt
    [...]
     open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 6
    -fstat(6, {st_mode=S_IFREG|0644, st_size=86, ...}) = 0
    -mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7fc033c61000
    -read(6, "# Generated by NetworkManager\nse"..., 4096) = 86
    +fstat(6, {st_mode=S_IFREG|0644, st_size=147, ...}) = 0
    +mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f63e868d000
    +read(6, "# Generated by NetworkManager\nse"..., 4096) = 147
     read(6, "", 4096)                       = 0
     close(6)                                = 0
    -munmap(0x7fc033c61000, 4096)            = 0
    +munmap(0x7f63e868d000, 4096)            = 0
     open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 6
     fstat(6, {st_mode=S_IFREG|0644, st_size=969, ...}) = 0
    -mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7fc033c61000
    +mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f63e868d000
     read(6, "127.0.0.1\tlocalhost\n127.0.1.1\tst"..., 4096) = 969
     read(6, "", 4096)                       = 0
     close(6)                                = 0
    -munmap(0x7fc033c61000, 4096)            = 0
    +munmap(0x7f63e868d000, 4096)            = 0
    +open("/etc/gai.conf", O_RDONLY|O_CLOEXEC) = 6
    +fstat(6, {st_mode=S_IFREG|0644, st_size=2614, ...}) = 0
    +fstat(6, {st_mode=S_IFREG|0644, st_size=2614, ...}) = 0
    +mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f63e868d000
    +read(6, "# Configuration for getaddrinfo("..., 4096) = 2614
    +read(6, "", 4096)                       = 0
    +close(6)                                = 0
    +munmap(0x7f63e868d000, 4096)            = 0
    +futex(0x7f63e7331f64, FUTEX_WAKE_PRIVATE, 2147483647) = 0
    +socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 6
    +connect(6, {sa_family=AF_INET, sin_port=htons(0), 
sin_addr=inet_addr("127.0.0.1")}, 16) = 0
    +getsockname(6, {sa_family=AF_INET, sin_port=htons(59592), 
sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
    +close(6)                                = 0
    +socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 6
    +connect(6, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, 
"::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
    +getsockname(6, {sa_family=AF_INET6, sin6_port=htons(42666), 
inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 
[28]) = 0
    +close(6)                                = 0
     open("/etc/nginx/fastcgi.conf", O_RDONLY) = 6
     fstat(6, {st_mode=S_IFREG|0644, st_size=1034, ...}) = 0
     pread(6, "\nfastcgi_param  SCRIPT_FILENAME "..., 1034, 0) = 1034
     [...]

After this part the output differs even more. The failed invocation
queries external DNS server for mylocalserver (with negative
response), while the correct invocation obtains the correct address
from /etc/hosts. Note that the strace output shows that /etc/hosts is
read in both cases.

Another difference seen in the strace output is that the content of
/etc/resolv.conf is different. I do not think that this matters but
for completeness, I include both versions of resolv.conf as well.
During the failed invocation, the content is:

    # Generated by NetworkManager
    search felk.cvut.cz
    nameserver 2001:718:2:1611:0:1:0:90

while during the correct one:

    # Generated by NetworkManager
    search feld.cvut.cz felk.cvut.cz
    nameserver 147.32.192.2
    nameserver 147.32.192.3
    nameserver 2001:718:2:1611:0:1:0:90

Best regards,
-Michal

-- System Information:
Debian Release: 8.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages nginx depends on:
ii  nginx-light  1.6.2-5

nginx recommends no packages.

nginx suggests no packages.

-- no debconf information


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to