# Nginx ignoring config file when started via systemd

**URL:** <https://www.ruby-forum.com/t/nginx-ignoring-config-file-when-started-via-systemd/243593>\
**Category:** NGINX\
**Created:** [December 8, 2015, 6:37am UTC](https://www.ruby-forum.com/t/nginx-ignoring-config-file-when-started-via-systemd/243593 "2015-12-08T06:37:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 8, 2015, 6:37am UTC](https://www.ruby-forum.com/t/nginx-ignoring-config-file-when-started-via-systemd/243593/1 "2015-12-08T06:37:16Z")

</div>

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:

> **[nginx ignoring config file when started via systemd](https://forum.nginx.org/read.php?2,263342,263342#msg-263342)**
>
> 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 defaul

---

<div class="post-metadata">

**Author:** ![theheadsage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@theheadsage](https://www.ruby-forum.com/u/theheadsage)\
**Post date:** [December 8, 2015, 7:29am UTC](https://www.ruby-forum.com/t/nginx-ignoring-config-file-when-started-via-systemd/243593/2 "2015-12-08T07:29:15Z")

</div>

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:

> **[Re: nginx ignoring config file when started via systemd](https://forum.nginx.org/read.php?2,263342,263343#msg-263343)**
>
> 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 defaul

---

<div class="post-metadata">

**Author:** ![theheadsage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@theheadsage](https://www.ruby-forum.com/u/theheadsage)\
**Post date:** [December 9, 2015, 8:59am UTC](https://www.ruby-forum.com/t/nginx-ignoring-config-file-when-started-via-systemd/243593/3 "2015-12-09T08:59:45Z")

</div>

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:

> **[Re: nginx ignoring config file when started via systemd](https://forum.nginx.org/read.php?2,263342,263359#msg-263359)**
>
> 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 defaul
