- 查看NGINX是否在运行.
1. 查看NGINX是否在运行.
ps aux | grep nginx
[root@bogon /]# ps aux | grep nginx root 2318 0.0 0.0 56816 1272 ? Ss 5月04 0:00 nginx: master process /usr/sbin/nginx nginx 2319 0.0 0.0 57264 2232 ? S 5月04 0:00 nginx: worker process nginx 2320 0.0 0.0 57264 2232 ? S 5月04 0:00 nginx: worker process nginx 2321 0.0 0.0 57264 1992 ? S 5月04 0:00 nginx: worker process nginx 2322 0.0 0.0 57264 1992 ? S 5月04 0:00 nginx: worker process nginx 2323 0.0 0.0 57264 2228 ? S 5月04 0:00 nginx: worker process nginx 2324 0.0 0.0 57264 2232 ? S 5月04 0:00 nginx: worker process nginx 2325 0.0 0.0 57264 2228 ? S 5月04 0:00 nginx: worker process nginx 2326 0.0 0.0 57264 1992 ? S 5月04 0:00 nginx: worker process root 21470 0.0 0.0 112732 968 pts/0 S+ 09:56 0:00 grep --color=auto nginx
第一种方法:查看进程列表并过滤
Linux每个应用运行都会产生一个进程,那么我们就可以通过查看Nginx进程是否存在来判断它是否启动。
用ps -ef列出进程列表,然后通过grep过滤。
如: ps -ef | grep nginx 就可以看到度Nginx进程是否存在了
ps -ef | grep httpd
netstat -tlnp | grep 端口号(默认是80)
lsof -i :端口号
第二种方法:直接查看进程id
ps -C nginx -o pid
这种直接返回pid的方式比较适合跟其他程序结合使用,比如在shell/python脚本中执行这个命令拿到pid,让后回根据pid来判断Nginx是否启动。
通过端口判断
第三种方法:使用netstat命令
如果我们的Nginx运行在80端口,那么就可以通过netstat -anp | grep :80命令来判断Nginx是否启动。
第四种方法:使用lsof命令
lsof -i:80 也可以查到80端口进程是否有进程在答运行。
ps -A | grep nginx 也可以
2. 查看NGINX配置是否正确
[root@bogon /]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx的配置文件的路径: /etc/nginx/nginx.conf
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
2019-10-11 C# MVC文件上传注意点
2019-10-11 C# MVC文件上传
2019-10-11 博客园怎么转载别人的文章
2019-10-11 MVC 控制器向View传值的三种方法(转) C#