[FIX] NGINX start failed CentOS 7 - nginx: [emer] open () “path” failed (13: Permission denied)

In terms of managing web servers, many unpleasant surprises can occur. Especially when moving from an older older version of an operating system to a new one. Vsalable for both Ubuntu as well as CentOS.

From the almost complete CentOS 5, the CentOS 7 a lot of things have changed for the better. The emphasis was very much on security and stability. For a linux novice, or for a user who is not aware of what is new in terms of servers and services specific to the administration of Web Hosting, little news can give you headaches.

One of the most common errors encountered when installing LEMP (Linux, NGINX, MySQL, PHP) security and service permissions installed on the operating system CentOS 7.

Failure to start the NGINX service even if everything seems to be well configured in terms of PHP-FPM and NGINX.

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

We have the following details in status, but they do not help us a lot.

systemctl status nginx.service
 ● nginx.service - The nginx HTTP and reverse proxy server
 Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
 Active: failed (Result: exit-code) since Fri 2019-03-08 06:57:41 UTC; 17s ago
 Process: 4405 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
 Process: 4704 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
 Process: 4766 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
 Process: 4764 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 4706 (code=exited, status=0/SUCCESS)
 Mar 08 06:57:40 srv.xsystem.dev systemd[1]: Starting The nginx HTTP and reverse proxy server...
 Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: [emerg] open() "/srv/www/web.dev/logs/access.log" failed (13: Permission denied)
 Mar 08 06:57:41 srv.xsystem.dev nginx[4766]: nginx: configuration file /etc/nginx/nginx.conf test failed
 Mar 08 06:57:41 srv.xsystem.dev systemd[1]: nginx.service: control process exited, code=exited status=1
 Mar 08 06:57:41 srv.xsystem.dev systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
 Mar 08 06:57:41 srv.xsystem.dev systemd[1]: Unit nginx.service entered failed state.
 Mar 08 06:57:41 srv.xsystem.dev systemd[1]: nginx.service failed.

We understand, however, that access to the "nginx" service is blocked CentOS 7.

Solving the problem "nginx: [emerg] open ()" path "failed (13: Permission denied)"

Security-Enhanced Linux (SELinux) is a module that most often comes activated with the installation CentOS 7 or other distributions of Linux. This module offers multiple control tools and control access at the server level, being a good guard when it comes to security and integrity. However, may limit the privileges of important services and applications, installed on the system.

The simple solution to the above problem is to disable it SELinux.

How we disable it SELinux on CentOS 7

1. First of all, check if this module is enabled on the system by executing the command “sestatus”.

 SELinux status:                 enabled
 SELinuxfs mount:                /sys/fs/selinux
 SELinux root directory:         /etc/selinux
 Loaded policy name:             targeted
 Current mode:                   enforcing
 Mode from config file:          enforcing
 Policy MLS status:              enabled
 Policy deny_unknown status:     allowed
 Max kernel policy version:      31

2. If the service is enabled, run the command line: "setenforce 0", then go and edit the file “/etc/selinux/config”.
Here you set:  SELINUX=disabled.

3. After saving the above file, restart the server.

Everything should work smoothly.

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » Noteworthy » [FIX] NGINX start failed CentOS 7 - nginx: [emer] open () “path” failed (13: Permission denied)

1 thought on “[FIX] NGINX start failed CentOS 7 - nginx: [emer] open () “path” failed (13: Permission denied) ”

Leave a Comment