nginx系列-01-常用命令

1 注意点

1.1 进程的身份

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

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

2 nginx命令行选项

2.1 启动和停止守护进程

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

CMDDESC
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 ~]#
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值