这篇文章主要介绍“Nginx配置文件的方法”,在日常操作中,相信很多人在Nginx配置文件的方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Nginx配置文件的方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
Nginx的配置语法
配置文件由指令与指令块构成
每条指令以;分号结尾,指令与参数以空格符号分隔
指令块以{}大括号将多条指令组织在一起
include语句允许组合多个配置文件以提升可维护性
使用#号添加注释,提高可读性
使用$符号使用变量
部分指令的参数支持正规表达式
配置参数的时间单位
配置参数的空间单位
Nginx命令行
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配置文件的方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/3242075/blog/3125412