nginx中解析php原理
apache —般是把php当做自己的一个模块来启动的.
而nginx则是把http请求变量(如get,user__agent等)转发给php进程.即php独立进程,与nginx 进行通信.称为fastcgi运行方式
Nginx 一般配置文件 位置 /usr/local/nginx/conf/nginx.conf
一、常用命令(已经加了环境变量)
请在执行下面命令时,确保权限正确,统一在命令前加入:sudo
,使用 root 权限操作 nginx。
- 查看 nginx 版本:
nginx -v
- 检查配置语法是否正确:
service nginx configtest
- 重启:
service nginx restart
- 停止:
service nginx stop
- 启动:
service nginx start
- 查看状态:
service nginx status
- 重新加载配置:service nginx reload
centoe7.x:
systemctl reload nginx.service
/bin/systemctl status nginx.service
/bin/systemctl stop nginx.service
/bin/systemctl start nginx.service
/bin/systemctl restart nginx.service
- 检查语法:nginx -t
Nginx reload和restart区别
reload,重新加载的意思,reload会重新加载配置文件,nginx服务不会中断,而且reload时会测试conf语法等,如果出错会rollback用上一次正确配置文件保持正常运行。
restart,重启,会重启nginx服务。这个重启会造成服务一瞬间的中断,当然如果配置文件出错会导致服务启动失败,那就是更长时间的服务中断了。
二、常用命令(没加环境变量)
假设Nginx安装在/usr/local/nginx
sudo /usr/local/nginx/nginx -s {参数}
./nginx 启动、等价于/usr/local/nginx/nginx
./nginx -s stop 停止、等价于/usr/local/nginx/nginx -s stop
./nginx -s quit 安全退出
./nginx -s reload 重新加载配置文件
ps aux|grep nginx 查看nginx进程
检查配置,同时也是输出配置文件所在位置:/usr/local/nginx/nginx -t
修改配置后重载:/usr/local/nginx/nginx -s reload
示例
cd /www/server/nginx/sbin/
#首先进入nginx安装目录
./nginx -v
nginx/1.21.4
#查看nginx版本
./nginx -s stop
#停止nginx服务
./nginx
#启动nginx服务
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#nginx指定配置文件启动
参数 “-c” 指定了配置文件的路径,如果不加 “-c” 参数,Nginx 会默认加载其安装目录的 conf 子目录中的 nginx.conf 文件。
三、停止方式
获取进程id
cat /usr/local/nginx/logs/nginx.pid
优雅重启
kill -HUP (进程号)
例:
kill -HUP 'cat /usr/local/nginx/logs/nginx.pid'
优雅停止
kill -QUIT (进程号)
暴力停止
kill -TERM (进程号)
kill -INT (进程号)
其他信号指令
kill -USR1 (进程号) //重读日志
kill -USR2 (进程号) //平滑升级
kill -WINCH (进程号) //优雅关闭旧的进程,配合USR2
强制停止
pkill -9 nginx
四、查找nginx安装目录
方法一:输入命令ps -ef | grep nginx
ps -ef | grep nginx
返回结果包含安装目录(进入目录启动)
root 2662 1 0 07:12 ? 00:00:00 nginx: master process /usr/sbin/nginx
或则返回(通过服务启动)
root 18905 1 0 4月29 ? 00:00:00 nginx: master process ./nginx
⽅法二:输入命令nginx -t
# nginx -t
返回结果包含配置文件目录
nginx: theconfigurationfile /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
⽅法三:输入代码 ll /proc/PID/exe
利⽤上⾯的命令查看nginx的PID,就⽤上图中的16150,然后通过该进程ID来查找当前运⾏的nginx⽬录,命令如下
ll /proc/16150/exe