Nginx ignoring config file when started via systemd

Hi Guys,

Got a somewhat interesting bug with nginx, which is where my config is
being
ignored by nginx when it’s started via systemd.

Here’s the config:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;

    location /nodejs/testnodebox {
        proxy_pass       http://127.0.0.1:7000;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

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

Now, this config works fine on another server, but on this one, when
started
via systemd, visiting the URL results in the nginx 404 page.

2015/12/08 16:23:16 [error] 64787#0: *1 open()
“/usr/share/nginx/html/nodejs/testnodebox” failed (2: No such file or
directory), client: , server: _, request: “GET /nodejs/testnodebox
HTTP/1.1”, host: “”

but if I kill nginx via systemctl stop nginx.service and start it
manually
via sudo nginx (in the /etc/nginx/ directory) it reads the config and
proxies requests fine:

- - [08/Dec/2015:16:34:30 +1100] “GET /nodejs/testnodebox HTTP/1.1”
200
33 “-” “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
like
Gecko) Chrome/46.0.2490.86 Safari/537.36” “-”

I’ve tried enabling the debug log and that hasn’t shown anything
helpful. So
I’m somewhat stuck. Any ideas on what might be causing this? Anywhere I
should be looking?

Thanks for you help,

Daniel Sage

Posted at Nginx Forum:

hi daniel,

hiw did you installed nginx, manually (self-compiled) or
through your distratos repo?

can you provide the nginx -V - output?

usually /etc/nginx/nginx.conf is the default-config, if not given;
nginx -V will tell what defaults arre used in your config.

cheers,

mex

Posted at Nginx Forum:

Hi mex,

It was installed via the RHEL 7 repo.

I’ve managed to solve the issue, and so for anyone else experiencing
this
odd behavour the solution is to check the SELINUX file context.

My config was in a file that had “unconfined_u:object_r:var_t:s0” and it
needed “unconfined_u:object_r:httpd_config_t:s0” so run “sudo restorecon
-v
/path/to/conf”

Otherwise nginx just silently ignores the file, and no error shows up in
the
audit.log file. (or disable SELINUX, but alas I can’t)

Regards,
Daniel Sage

Posted at Nginx Forum: