1. 查看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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM