运行sudo service nginx restart,报错* Restarting nginx nginx[fail],启动不了nginx,启动nginx报错

//运行sudo service nginx restart报错
root@iZm5e3iekfi2rh6udbikaZ:/etc# sudo service nginx restart
 * Restarting nginx nginx                                        [fail]

//运行sudo service nginx start没有返回消息
root@iZm5e3iekfi2rh6udbikaZ:/etc# sudo service nginx start

//查看nginx进程,也没有响应的nginx进程
root@iZm5e3iekfi2rh6udbikaZ:/etc# ps -axu | grep nginx
root     17194  0.0  0.0  11760  2260 pts/4    S+   10:41   0:00 grep --color=auto nginx

解决的方法就是查看当前nginx是因为什么报错

//输入sudo nginx -t,查看错误原因
root@iZm5e3iekfi2rh6udbikaZ:/etc/nginx/conf.d# sudo nginx -t
//返回报错原因,我的错误原因是因为family1.conf文件的第22行少了一个";" 或者 "}"
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/family1.conf:22
nginx: configuration file /etc/nginx/nginx.conf test failed

根据返回的错误原因修改了之后,再次运行sudo nginx -t,现在已经正确了

root@iZm5e3iekfi2rh6udbikaZ:/etc/nginx/conf.d# sudo nginx -t
//返回正确的信息
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

再次启动nginx

//运行sudo service nginx start
root@iZm5e3iekfi2rh6udbikaZ:/etc/nginx/conf.d# sudo service nginx start

//查看nginx进程,可以看到nginx的进程,现在启动成功了~
root@iZm5e3iekfi2rh6udbikaZ:/etc/nginx/conf.d# ps -axu | grep nginx
root     17374  0.0  0.0  77932  2772 ?        Ss   11:00   0:00 nginx: master process /usr/sbin/nginx
root     17375  0.0  0.0  78280  3324 ?        S    11:00   0:00 nginx: worker process
root     17376  0.0  0.0  78280  3324 ?        S    11:00   0:00 nginx: worker process
root     17377  0.0  0.0  78280  3324 ?        S    11:00   0:00 nginx: worker process
root     17378  0.0  0.0  78280  3324 ?        S    11:00   0:00 nginx: worker process
root     17380  0.0  0.0  11760  2164 pts/4    S+   11:00   0:00 grep --color=auto nginx
发布了131 篇原创文章 · 获赞 136 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/shine_a/article/details/103045459
今日推荐