问题描述:
启动nginx的时候出现Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details
使用sudo systemctl status nginx 查看nginx的状态。出现:
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 Mon 2020-08-31 18:35:16 PDT; 11min ago
Aug 31 18:35:16 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Aug 31 18:35:16 localhost.localdomain nginx[4027]: nginx: [emerg] open() "/etc/nginx/conf.d/nginx.conf" failed (13: Permission denied) in /etc/nginx/nginx.conf:36
Aug 31 18:35:16 localhost.localdomain nginx[4027]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 31 18:35:16 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Aug 31 18:35:16 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Aug 31 18:35:16 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Aug 31 18:35:16 localhost.localdomain systemd[1]: nginx.service failed.
这时候应该是SELINUX这个东东在搞怪(不知道selinux的自行谷歌)
使用命令:
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
修改selinux的状态,它默认是开启的
sudo vim /etc/selinux/config (将SELINUX=enforcig改为SELINUX=disabled)
sudo setenforce 0 (临时关闭SELINUX)
sudo systemctl start nginx
sudo systemctl enable nginx
不出意外的话,这样你的nginx就起来了