nginx doesn't come up when run via SystemD

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I installed mainline nginx 1.13.9 using the provided rpm on CentOS 7.4. I had to use this rpm because I am forced to do yum localinstall due to company governance.



My problem is that systemctl start nginx always yields this:



Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.



journalctl tells me:



Mar 07 08:57:05 myhost nginx[19466]: nginx: [emerg] open() "/var/opt/nginx/config/nginx.conf" failed (13: Permission denied)



(What you see here is another company thing: I mustn't put the conf files under etc, I have to keep them in a directory where I don't need root permissions to change them)



These are the permissions set for the nginx.conf:



-rw-r--r--. 1 nginx nginx 241 Mar 7 09:17 nginx.conf



I reduced the nginx.conf to an (I guess) absolute minimum and even tried to put log files, pid and alike to directories where permissions are granted for sure. The error log contains absolutely nothing.



This is my reduced nginx.conf:



user nginx nginx;
pid /tmp/nginx.pid;
error_log /tmp/error.log debug;

events


http
default_type application/octet-stream;
charset UTF-8;

server
listen 8080;
location /
root /tmp/;





And this is my slightly modified nginx.service definition:



[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


(You can see that I tried to force an error_log just in case nginx fails before the nginx.conf is read)



When I do sudo -u nginx /usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;" this works just fine. Despite of a short warning the process starts up fine:



nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /var/opt/nginx/config/nginx.conf:1


I am sure it must be some stupid mistake, but I have no clue which.







share|improve this question




















  • Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
    – Yurij Goncharuk
    Mar 7 at 8:49










  • @YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
    – Marged
    Mar 7 at 9:53











  • Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
    – Yurij Goncharuk
    Mar 7 at 10:49










  • @YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
    – Marged
    Mar 7 at 11:26






  • 1




    I think about it. If you have been solved problerm, please don't forget to post solution.
    – Yurij Goncharuk
    Mar 7 at 11:30














up vote
1
down vote

favorite












I installed mainline nginx 1.13.9 using the provided rpm on CentOS 7.4. I had to use this rpm because I am forced to do yum localinstall due to company governance.



My problem is that systemctl start nginx always yields this:



Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.



journalctl tells me:



Mar 07 08:57:05 myhost nginx[19466]: nginx: [emerg] open() "/var/opt/nginx/config/nginx.conf" failed (13: Permission denied)



(What you see here is another company thing: I mustn't put the conf files under etc, I have to keep them in a directory where I don't need root permissions to change them)



These are the permissions set for the nginx.conf:



-rw-r--r--. 1 nginx nginx 241 Mar 7 09:17 nginx.conf



I reduced the nginx.conf to an (I guess) absolute minimum and even tried to put log files, pid and alike to directories where permissions are granted for sure. The error log contains absolutely nothing.



This is my reduced nginx.conf:



user nginx nginx;
pid /tmp/nginx.pid;
error_log /tmp/error.log debug;

events


http
default_type application/octet-stream;
charset UTF-8;

server
listen 8080;
location /
root /tmp/;





And this is my slightly modified nginx.service definition:



[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


(You can see that I tried to force an error_log just in case nginx fails before the nginx.conf is read)



When I do sudo -u nginx /usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;" this works just fine. Despite of a short warning the process starts up fine:



nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /var/opt/nginx/config/nginx.conf:1


I am sure it must be some stupid mistake, but I have no clue which.







share|improve this question




















  • Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
    – Yurij Goncharuk
    Mar 7 at 8:49










  • @YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
    – Marged
    Mar 7 at 9:53











  • Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
    – Yurij Goncharuk
    Mar 7 at 10:49










  • @YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
    – Marged
    Mar 7 at 11:26






  • 1




    I think about it. If you have been solved problerm, please don't forget to post solution.
    – Yurij Goncharuk
    Mar 7 at 11:30












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I installed mainline nginx 1.13.9 using the provided rpm on CentOS 7.4. I had to use this rpm because I am forced to do yum localinstall due to company governance.



My problem is that systemctl start nginx always yields this:



Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.



journalctl tells me:



Mar 07 08:57:05 myhost nginx[19466]: nginx: [emerg] open() "/var/opt/nginx/config/nginx.conf" failed (13: Permission denied)



(What you see here is another company thing: I mustn't put the conf files under etc, I have to keep them in a directory where I don't need root permissions to change them)



These are the permissions set for the nginx.conf:



-rw-r--r--. 1 nginx nginx 241 Mar 7 09:17 nginx.conf



I reduced the nginx.conf to an (I guess) absolute minimum and even tried to put log files, pid and alike to directories where permissions are granted for sure. The error log contains absolutely nothing.



This is my reduced nginx.conf:



user nginx nginx;
pid /tmp/nginx.pid;
error_log /tmp/error.log debug;

events


http
default_type application/octet-stream;
charset UTF-8;

server
listen 8080;
location /
root /tmp/;





And this is my slightly modified nginx.service definition:



[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


(You can see that I tried to force an error_log just in case nginx fails before the nginx.conf is read)



When I do sudo -u nginx /usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;" this works just fine. Despite of a short warning the process starts up fine:



nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /var/opt/nginx/config/nginx.conf:1


I am sure it must be some stupid mistake, but I have no clue which.







share|improve this question












I installed mainline nginx 1.13.9 using the provided rpm on CentOS 7.4. I had to use this rpm because I am forced to do yum localinstall due to company governance.



My problem is that systemctl start nginx always yields this:



Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.



journalctl tells me:



Mar 07 08:57:05 myhost nginx[19466]: nginx: [emerg] open() "/var/opt/nginx/config/nginx.conf" failed (13: Permission denied)



(What you see here is another company thing: I mustn't put the conf files under etc, I have to keep them in a directory where I don't need root permissions to change them)



These are the permissions set for the nginx.conf:



-rw-r--r--. 1 nginx nginx 241 Mar 7 09:17 nginx.conf



I reduced the nginx.conf to an (I guess) absolute minimum and even tried to put log files, pid and alike to directories where permissions are granted for sure. The error log contains absolutely nothing.



This is my reduced nginx.conf:



user nginx nginx;
pid /tmp/nginx.pid;
error_log /tmp/error.log debug;

events


http
default_type application/octet-stream;
charset UTF-8;

server
listen 8080;
location /
root /tmp/;





And this is my slightly modified nginx.service definition:



[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


(You can see that I tried to force an error_log just in case nginx fails before the nginx.conf is read)



When I do sudo -u nginx /usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;" this works just fine. Despite of a short warning the process starts up fine:



nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /var/opt/nginx/config/nginx.conf:1


I am sure it must be some stupid mistake, but I have no clue which.









share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 8:29









Marged

17118




17118











  • Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
    – Yurij Goncharuk
    Mar 7 at 8:49










  • @YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
    – Marged
    Mar 7 at 9:53











  • Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
    – Yurij Goncharuk
    Mar 7 at 10:49










  • @YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
    – Marged
    Mar 7 at 11:26






  • 1




    I think about it. If you have been solved problerm, please don't forget to post solution.
    – Yurij Goncharuk
    Mar 7 at 11:30
















  • Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
    – Yurij Goncharuk
    Mar 7 at 8:49










  • @YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
    – Marged
    Mar 7 at 9:53











  • Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
    – Yurij Goncharuk
    Mar 7 at 10:49










  • @YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
    – Marged
    Mar 7 at 11:26






  • 1




    I think about it. If you have been solved problerm, please don't forget to post solution.
    – Yurij Goncharuk
    Mar 7 at 11:30















Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
– Yurij Goncharuk
Mar 7 at 8:49




Stupid suggestion, but check in that all path of /var/opt/nginx/config/ is accessible to user 'nginx'. Maybe one directory in chain doesn't have enough permissions for user 'nginx'.
– Yurij Goncharuk
Mar 7 at 8:49












@YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
– Marged
Mar 7 at 9:53





@YurijGoncharuk: Thanks for the suggestion. I checked this and others has at least r (var and opt) and further down the chain even w
– Marged
Mar 7 at 9:53













Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
– Yurij Goncharuk
Mar 7 at 10:49




Sometimes, in situations like this I login as necessary user ('nginx' in this situation) and trying to do something like read/write some files. Offcause, it's need to add possibility to login for that user (cmdline interpret is disabled by default) in /etc/passwd. It's dirty way, but sometimes is helpful for me.
– Yurij Goncharuk
Mar 7 at 10:49












@YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
– Marged
Mar 7 at 11:26




@YurijGoncharuk Thanks for that suggestion, I already removed nologin from the user and tried su nginx (which has limitations) and sudo -u nginx ... (see above). There everything works, but not when run by SystemD
– Marged
Mar 7 at 11:26




1




1




I think about it. If you have been solved problerm, please don't forget to post solution.
– Yurij Goncharuk
Mar 7 at 11:30




I think about it. If you have been solved problerm, please don't forget to post solution.
– Yurij Goncharuk
Mar 7 at 11:30










1 Answer
1






active

oldest

votes

















up vote
0
down vote













This problem was caused by two mistakes I made:



  • incorrect directory permissions

  • a missing group membership

One of the directories was missing the x, so the process couldn't traverse the path. I had to chmod g+X it.
In addition to that I had to add the technical user of nginx (which in my scenario is not the default nginx) to the nginx group.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428689%2fnginx-doesnt-come-up-when-run-via-systemd%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This problem was caused by two mistakes I made:



    • incorrect directory permissions

    • a missing group membership

    One of the directories was missing the x, so the process couldn't traverse the path. I had to chmod g+X it.
    In addition to that I had to add the technical user of nginx (which in my scenario is not the default nginx) to the nginx group.






    share|improve this answer
























      up vote
      0
      down vote













      This problem was caused by two mistakes I made:



      • incorrect directory permissions

      • a missing group membership

      One of the directories was missing the x, so the process couldn't traverse the path. I had to chmod g+X it.
      In addition to that I had to add the technical user of nginx (which in my scenario is not the default nginx) to the nginx group.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        This problem was caused by two mistakes I made:



        • incorrect directory permissions

        • a missing group membership

        One of the directories was missing the x, so the process couldn't traverse the path. I had to chmod g+X it.
        In addition to that I had to add the technical user of nginx (which in my scenario is not the default nginx) to the nginx group.






        share|improve this answer












        This problem was caused by two mistakes I made:



        • incorrect directory permissions

        • a missing group membership

        One of the directories was missing the x, so the process couldn't traverse the path. I had to chmod g+X it.
        In addition to that I had to add the technical user of nginx (which in my scenario is not the default nginx) to the nginx group.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 8 at 5:04









        Marged

        17118




        17118






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428689%2fnginx-doesnt-come-up-when-run-via-systemd%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay