[root@localhost web]# sudo systemctl 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.
[root@localhost web]#
[root@localhost web]#
[root@localhost web]#
[root@localhost web]# 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 六 2025-08-30 14:21:25 CST; 6s ago
  Process: 4701 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
  Process: 4689 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

8月 30 14:21:24 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
8月 30 14:21:25 localhost.localdomain nginx[4701]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
8月 30 14:21:25 localhost.localdomain nginx[4701]: nginx: [emerg] bind() to 0.0.0.0:28011 failed (13: Permission denied)
8月 30 14:21:25 localhost.localdomain nginx[4701]: nginx: configuration file /etc/nginx/nginx.conf test failed
8月 30 14:21:25 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
8月 30 14:21:25 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
8月 30 14:21:25 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
8月 30 14:21:25 localhost.localdomain systemd[1]: nginx.service failed.

执行下面代码,问题解决:
[root@localhost web]# sudo semanage port -a -t http_port_t -p tcp 28011
[root@localhost web]# sudo systemctl restart nginx

推荐解决方案

根据您的错误信息,最可能的原因是SELinux策略。请按以下步骤操作:

  1. 临时解决方案(测试用)

    bash

    sudo setenforce 0
    sudo systemctl restart nginx
  2. 永久解决方案

    bash

    # 安装semanage工具(如果尚未安装)
    sudo yum install policycoreutils-python-utils
    
    # 将28011端口添加到SELinux的HTTP允许端口
    sudo semanage port -a -t http_port_t -p tcp 28011
    # 查看SELinux的HTTP允许端口 
    semanage port -l | grep http
    
    # 重启SELinux和Nginx
    sudo setenforce 1
    sudo systemctl restart nginx

接下来可能遇见的问题及解决方案

启动成功后,如果访问Nginx 前端页面,接口报502 Bad Gateway,可能是限制了Nginx访问http网络,点击查看解决方案允许 httpd 网络连接

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐