Welcome! Log In Create A New Profile

Advanced

systemctl cannot start nginx when access_log is set to /tmp/nginx/access.log

Posted by iapdog 
systemctl cannot start nginx when access_log is set to /tmp/nginx/access.log
June 14, 2020 09:19PM
I happened to find this annoying issue - not sure this is a systemctl issue or an nginx problem.

The issue is reproducible on amazonlinux2 and centos8 (I tried both on AWS EC2)

steps to re-produce:

in /etc/nginx/nginx.conf

change the line from:
access_log /var/log/nginx/access.log main;

to:
access_log /tmp/bbb/access.log main;

and mkdir /var/bbb/ set the ownership and mode to match /var/log/nginx/
now run systemctl start nginx. The nginx won't start. The log says:

<code>
‚óŹ nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2020-06-15 01:13:19 UTC; 5s ago
Process: 32642 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 32626 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Jun 15 01:13:18 ip-10-161-21-238.ec2.internal systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 15 01:13:18 ip-10-161-21-238.ec2.internal nginx[32642]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jun 15 01:13:18 ip-10-161-21-238.ec2.internal nginx[32642]: nginx: [emerg] open() "/tmp/bbb/access.log" failed (2: No such file or directory)
Jun 15 01:13:18 ip-10-161-21-238.ec2.internal nginx[32642]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jun 15 01:13:19 ip-10-161-21-238.ec2.internal systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 15 01:13:19 ip-10-161-21-238.ec2.internal systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jun 15 01:13:19 ip-10-161-21-238.ec2.internal systemd[1]: Unit nginx.service entered failed state.
Jun 15 01:13:19 ip-10-161-21-238.ec2.internal systemd[1]: nginx.service failed.
</code>


I don't have to write the access_log to /tmp/ as it is not a good practice.
I just found this error while I was trying something. If I set access_log to be /tmp/access.log, it works. I am very interested to find out what causes this inconsistency.
Re: systemctl cannot start nginx when access_log is set to /tmp/nginx/access.log
June 15, 2020 01:22PM
I got the answer for this - actually this is by design:

The nginx service[0] in RHEL/CentOS 8 uses PrivateTmp=true directive so it doesn't see the /tmp/nginx directory you just created. You could either add a service dropin with ExecStartPre= which will do the log directory setup or drop PrivateTmp=true to make this work.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 48
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready