进入nginx的sbin目录下
cd /usr/local/nginx/sbin/
1、启动nginx
./nginx
2、停止nginx两种方式
#待nginx进程处理任务完毕进行停止。
./nginx -s quit
#先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s stop
3、查看nginx端口
ps aux|grep nginx
4、查看nginx版本号
/usr/local/bin » ./nginx -V nginx version: nginx/1.19.2 built by clang 11.0.3 (clang-1103.0.32.62) built with OpenSSL 1.1.1g 21 Apr 2020 TLS SNI support enabled
5、重启nginx
a,对 nginx 进行重启先停止再启动,即先执行停止命令再执行启动命令
./nginx -s quit ./nginx
b,重新加载配置文件,当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
6、开机启动
#如果想设开机启动的话
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist(取消开机启动)
7、安装位置
网站根目录在:/usr/local/var/www nginx配置文件位置:/usr/local/etc/nginx 注意:nginx被安装到的目录位置:/usr/local/Cellar/nginx 默认端口:80
8、查看帮助
/usr/local/etc/nginx » nginx -h nginx version: nginx/1.19.2 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.19.2/) -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
9、判断配置文件是否有问题
/usr/local/etc/nginx » nginx -t nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
10、停止nginx服务的其他的方法
查看nginx进程,进程号,停止的话可以杀进程
查看nginx进程:ps -ef|grep nginx
sudo kill -QUIT //主进程号
sudo kill -TERM //主进程号
/usr/local/etc/nginx » ps -ef|grep nginx 501 3213 1 0 10:00上午 ?? 0:00.00 nginx: master process /Applications/phpstudy/Extensions/Nginx1.16.1/sbin/nginx -p /Applications/phpstudy/Extensions/Nginx1.16.1/ 501 3214 3213 0 10:00上午 ?? 0:00.01 nginx: worker process 501 3215 3213 0 10:00上午 ?? 0:00.01 nginx: worker process 501 3216 3213 0 10:00上午 ?? 0:00.05 nginx: worker process 501 3217 3213 0 10:00上午 ?? 0:00.02 nginx: worker process 501 7114 6417 0 11:02上午 ttys001 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx ------------------------------------------------------------ /usr/local/etc/nginx »