nginx的常用命令以及root和alias之间的区别(alias是一个目录别名的定义,root则是最上层目录的定义)

常用命令

使用/usr/local/nginx/sbin/nginx -h命令查看可用参数:
[root@localhost ~]# /usr/local/nginx/sbin/nginx  -h
nginx version: nginx/1.16.0
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/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

参数解读:

v      可查看nginx的版本。
-V      可查看nginx的详细信息,包括编译的参数。
-t      可用来测试nginx的配置文件的语法错误。
-T      可用来测试nginx的配置文件语法错误,同时还可以通过重定向备份nginx的配置文件。
-q      如果配置文件没有错误信息时,不会有任何提示,如果有错误,则提示错误信息,与-t配合使用。
-s      发送信号给master处理:
        stop    立刻停止nginx服务,不管请求是否处理完
        quit    优雅的退出服务,处理完当前的请求退出
        reopen  重新打开日志文件,原日志文件要提前备份改名。
        reload  重载配置文件
-p      设置nginx家目录路径,默认是编译时的安装路径
-c      设置nginx的配置文件,默认是家目录下的配置文件
-g      设置nginx的全局变量,这个变量会覆盖配置文件中的变量。

root与alisa的区别

location /img/ {
    alias /var/www/image/;
}
#若按照上述配置的话,当客户端请求访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件

location /img/ {
    root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件. 

注:还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可无~~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值