这篇文章主要介绍“Nginx配置文件的方法”,在日常操作中,相信很多人在Nginx配置文件的方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Nginx配置文件的方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
配置文件由指令与指令块构成
每条指令以;分号结尾,指令与参数以空格符号分隔
指令块以{}大括号将多条指令组织在一起
include语句允许组合多个配置文件以提升可维护性
使用#号添加注释,提高可读性
使用$符号使用变量
部分指令的参数支持正规表达式


1.nginx 发送信号
#发送reload信号 重新加载配置文件(同kill -9)
[root@i-vvwtw5ne sbin]# ./nginx -s reload
#发送stop信号 立刻停止服务
[root@i-vvwtw5ne sbin]# ./nginx -s stop
#发送quit信号 优雅的停止服务
[root@i-vvwtw5ne sbin]# ./nginx -s quit
#发送reopen信号 重新开始记录日志文件
[root@i-vvwtw5ne sbin]# ./nginx -s reopen
2. 获取nginx的帮助
[root@i-vvwtw5ne sbin]# ./nginx -h
nginx version: nginx/1.16.1
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: /opt/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
3. nginx默认用$installPath/conf/nginx.conf的配置文件,也可以使用指定的配置文件,如下
[root@i-vvwtw5ne sbin]# ./nginx -c /opt/nginx/conf/mynginx.conf
4. 测试配置文件是否有语法错误
[root@i-vvwtw5ne sbin]# ./nginx -t
5. 打印nignx的版本信息
[root@i-vvwtw5ne sbin]# ./nginx -v
到此,关于“Nginx配置文件的方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!