启动 Nginx
nginx安装完成后,切换到nginx安装目录中的sbin目录(如果在执行 ./configure
没有指定额外的参数,则sbin目录为默认目录,否则切换到自定义目录),通过执行该目录下nginx编译后的二进制文件即可启动程序。
cd /usr/local/nginx/sbin/nginx
./nginx
执行上面的操作后,成功启动nginx,程序是没有任何提示的。我们可以使用ps命令查看nginx的运行状态,具体命令如下:
ps -ef | grep nginx
root 74751 1 0 19:51 ? 00:00:00 nginx: master process /usr/local/nginx/nginx
nobody 74752 74751 0 19:51 ? 00:00:00 nginx: worker process
nobody 74753 74751 0 19:51 ? 00:00:00 nginx: worker process
nobody 74754 74751 0 19:51 ? 00:00:00 nginx: worker process
nobody 74755 74751 0 19:51 ? 00:00:00 nginx: worker process
root 77668 19244 0 20:51 pts/0 00:00:00 grep --color=auto nginx
上面结果说明:
前面5行分别是nginx主进程(master process)和工作进程(worker process),最后一行是grep nginx命令。当看到这两个nginx进程时,说明nginx已经启动。
从第1列可以看出,nginx主进程以root用户运行,而工作进程以nobody用户运行,第二列显示了5个进程的ID(即PID),分别为:74751 74752 74753 74754和74755
注意:进程数是由电脑本身的处理器数量以及在Nginx配置文件中指定的数量综合决定的,所以每个人看到的可能不一样。
Nginx启动后,安装目录下,logs目录中会有ngxin.pid文件,可以使用 cat
命令查看进程号
cd /usr/local/nginx/logs
cat nginx.pid