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.
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.