文章目录
1, 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@laoban html]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
2,先检查nginx配置文件正否正确
nginx -t -c /etc/nginx/nginx.conf
发现配置文件没问题。
如果配置文件有错误,修改配置文件后,先执行nginx -t -c
命令检查配置文件无错误后,再执行nginx -s reload
重新加载配置文件命令。‘=
nginx -s reload -c /etc/nginx/nginx.conf
3,查看nginx服务状态,根据服务状态去判断报错原因
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/e68179a908b54e67b45ce031222e95dc.png)
日志说 `nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)`
大致意思就是绑定80端口失败,这个地址已经被用了
-
-
# 4,查看80端口被哪些程序所占用,输入如下命令
```c
netstat -tunlp | grep 80
发现进程httpd ,这个东西占据了主机的80端口,然后我们要杀掉这个httpd这个进程。使用kill命令,但是前提还得知道httpd的进程id是多少。
- A,查看httpd这个进程的进程id号
ps -ef | grep httpd
显示的结果,从左往右数,分别是
1,UID
:用户 ID。
2,PID
:进程 ID。
3,PPID
:父进程 ID。
4,C
:CPU 使用率。
5,STIME
:进程启动时间。
6,TTY
:终端名称。
7,TIME
:进程运行时间。
8,CMD
:启动该进程的命令
比如结果的第一行是root 1050 1 0 19:04 ? 00:00:01 /usr/sbin/httpd -DFOREGROUND
意思就是,用户ID是root;且进程ID是1050;进程 ID为1050的这个进程他的老爸进程ID是1;CPU使用率为0;启动进程 ID为1050的这个进程的时间点为19:04,对应的终端名称是未知显示为?;进程 ID为1050的这个进程已经运行了1秒钟; 启动进程 ID为1050的这个进程的命令是 /usr/sbin/httpd -DFOREGROUND
- B 杀掉这个进程
kill -9 1050
4,重启nginx
systemctl start nginx
看到没,没报错。
5,再查看nginx服务状态
systemctl status nginx.service
用浏览器去访问机器IP:80
,就可以看到nginx初始页面了。ll