[emerg] open() "/etc/nginx/nginx.conf" failed (13: Permission denied) after configuration restore
0 reputation · 08 Feb 2021, 06:49 UTC
0 reputation · 08 Feb 2021, 06:49 UTC
After restoring an nginx configuration from a backup, the goal is to have the service start successfully and serve content using the restored files.
The restored files must retain the original ownership (root:root) and permissions (644 for files, 755 for directories), and any SELinux contexts must match the original policy; otherwise the nginx worker process fails to open nginx.conf with a "[emerg] open() \"/etc/nginx/nginx.conf\" failed (13: Permission denied)" error even though the syntax is correct. nginx does not automatically detect that files have been replaced; an explicit reload or restart is required, and a failed reload can leave the old master process running while workers exit, which may mask partial restoration problems.
35775 reputation · 08 Feb 2021, 14:56 UTC
Automatic Detection: Nginx does not automatically detect changes to its configuration files. The master process reads nginx.conf only during the initial startup or when it receives an explicit signal (SIGHUP) via a reload or restart command.
Reload Verification: To ensure a reload has fully applied the restored configuration without leaving stale processes, first run nginx -t to validate syntax. After executing nginx -s reload, verify the process tree using ps auxf. You should see a single master process with new worker process IDs (PIDs); if multiple master processes exist, the reload failed or a stale process is lingering.
Persistent Permission Errors: Yes, a "Permission denied (13)" error can persist despite root:root ownership and 644 permissions if Mandatory Access Control (MAC) systems like SELinux or AppArmor are active. These systems evaluate security contexts and profiles independently of standard Linux DAC permissions.
+x) permissions on every parent directory in the path (/etc and /etc/nginx) to access the configuration file.When standard permissions are correct, the failure is typically caused by an incorrect SELinux security context (e.g., the restored file lacks the httpd_config_t type) or an AppArmor profile restricting access to the specific restored path.
restorecon -Rv /etc/nginxstat /etc /etc/nginxnginx -t && nginx -s reloadps auxf | grep nginxAssumption: This guide assumes a standard Linux distribution (e.g., RHEL, CentOS, or Ubuntu) where Nginx is managed by a master process running as root.
Diagnostic Detail Needed: Are you running Nginx inside a container? If so, the issue may stem from the host's security labels or the container's securityContext rather than the internal file permissions.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.