nginx系列-01-常用命令

[TOC]

1 注意点

1.1 进程的身份

在Linux等大多数由Unix发展而来的操作系统上,普通用户的进程只能监听在1024以上的端口。至于1024以下的端口比如80、443等需要由root身份的进程来监听。

因此请注意,Nginx的master进程的执行身份应该是root。

2 nginx命令行选项

2.1 启动和停止守护进程

nginx的启停控制可以通过-s选项向nginx发送signal来达到目的。
以下是 -s 选项的相关信号及其意义:

CMD DESC
nginx -c /path/to/conf 启动nginx,如果被指定配置文件,会使用默认的/etc/nginx/nginx.conf作为配置文件
nginx -s stop 立即停止(TERM信号)
nginx -s quit 优雅地停止(QUIT信号)
nginx -s reopen 重新打开日志文件
nginx -s reload 重新加载配置文件

2.2 测试配置文件

在执行命令前,nginx会首先去确认配置文件的语法格式。如果语法格式有误,不论提交什么命令都会失败。
有时候你的配置文件被修改出错,很可能无法正常停止nginx服务。或许只能使用 killall nginx来强行杀死了。

所以再修改了配置文件之后,重新载入新的配置之前,检测一下配置文件的语法格式还是很有必要。

语法格式测试

可以使用 -t 选项来测试配置文件语法格式

[root@VM_15_242_centos ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

有效性测试

通过语法测试,并不一定就代表配置文件真的是没问题的。

可以通过-c选项来进一步进行测试

[root@VM_15_242_centos ~]# nginx -t -c /home/hylexus/nginx-new.conf 
nginx: the configuration file /home/hylexus/nginx-new.conf syntax is ok
nginx: configuration file /home/hylexus/nginx-new.conf test is successful

2.3 其他选项

  • -v:显示简要的版本信息
[root@VM_15_242_centos ~]# nginx -v
nginx version: nginx/1.10.2
  • -V:更加详细信息
[root@VM_15_242_centos ~]# nginx -V
nginx version: nginx/1.10.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
[root@VM_15_242_centos ~]#
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 14,182评论 2 33
  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,862评论 24 1,002
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 99,761评论 9 468
  • 夜半,收到一个朋友的信息:你劝劝杨月吧,她正一步步滑向毁灭的深渊。十头牛也拉不回来了,看着她我心碎,我毫无办法。今...
    云水禅心千古情阅读 3,805评论 1 0