此博文详细罗列出在使用 nginx的一些注意点,长期更新!
常用命令:
- nginx -s stop 关闭nginx进程
- nginx –t 检查配置文件是否有误
- nginx -c filename 为 Nginx 指定一个配置文件
- nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载
- nginx -V 显示 nginx 的版本,编译器版本和配置参数
搭配Bat脚本也可以使用:
@echo off
rem 如果启动前已经启动nginx并记录下pid文件,会kill指定进程
nginx.exe -s stop
rem 测试配置文件语法正确性
nginx.exe -t -c conf/nginx.conf
rem 显示版本信息
nginx.exe -v
rem 按照指定配置去启动nginx
nginx.exe -c conf/nginx.conf
如果虚拟机或者本地有两个nginx?
cd到nginx的sbin目录下指定nginx的配置文件
[root@localhost sbin]# ./nginx -c /opt/nginx/conf/nginx.conf
配置文件做了修改或者项目的部署包有改动?
重新部署Vue项目会生成dist文件夹,将文件夹放到服务器后,查出当前vue项目端口的进程
[root@localhost sbin]# lsof -i:port
然后使用 kill 命令干掉占用 port 端口的应用,指定配置文件,重新加载nginx
[root@localhost sbin]# lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 7672 root 8u IPv4 52039357 0t0 TCP *:vcom-tunnel (LISTEN)
nginx 7683 nobody 8u IPv4 52039357 0t0 TCP *:vcom-tunnel (LISTEN)
[root@localhost sbin]# kill -9 7672
[root@localhost sbin]# kill -9 7683
[root@localhost sbin]# ./nginx -c /opt/nginx/conf/nginx.conf
[root@localhost sbin]# ./nginx -s reload
未完结!