解决nginx提示:(code=exited, status=203/EXEC)的错误

本文描述了在 CentOS 7 上编译安装的 nginx 1.19 启动时遇到的问题,重点在于 systemctl 启动时配置文件路径错误。通过备份原有配置、修改启动参数并重启系统,作者详细展示了修复步骤和解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目场景:

在centos7上启动nginx1.19.安装过程省略...

问题描述:

编译安装一切顺利,使用systemctl start nginx时提示如下内容:

[root@localhost stream_conf]# systemctl status nginx
● nginx.service - nginx - web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 二 2021-12-14 14:58:49 CST; 36s ago
  Process: 22970 ExecStartPre=/opt/server/nginx/sbin/nginx -t -c /opt/server/nginx/conf/nginx.conf (code=exited, status=203/EXEC)

1214 14:58:49 localhost.localdomain systemd[1]: Starting nginx - web server...
1214 14:58:49 localhost.localdomain systemd[22970]: Failed at step EXEC spawning /opt/server/nginx/sbin/nginx: No such file or directory
1214 14:58:49 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=203
1214 14:58:49 localhost.localdomain systemd[1]: Failed to start nginx - web server.
1214 14:58:49 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
1214 14:58:49 localhost.localdomain systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

重点报错内容:(code=exited, status=203/EXEC)


原因分析:

设置systemctl启动方式时出现配置文件(nginx.conf)的有效路径错误。


解决方案:

配置方法如下:

--先备份
[rot@localhost stream_conf]# cp /usr/lib/systemd/system/nginx.service /usr/lib/systemd/system/nginx.service.bak
--修改参数
[root@localhost stream_conf]# vim /usr/lib/systemd/system/nginx.service
--以下为原文件
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/server/nginx/conf/nginx.pid
ExecStartPre=/opt/server/nginx/sbin/nginx -t -c /opt/server/nginx/conf/nginx.conf
ExecStart=/opt/server/nginx/sbin/nginx -c /opt/server/nginx/conf/nginx.conf
ExecReload=/opt/server/nginx/sbin/nginx -s reload
ExecStop=/opt/server/nginx/sbin/nginx -s stop
ExecQuit=/opt/server/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

--修改为
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

--然后重启systemctl
[rot@localhost stream_conf]# systemctl daemon-reload

---尝试启动nginx
[root@localhost stream_conf]# systemctl start nginx
[root@localhost stream_conf]# systemctl status nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值