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则可有可无~~

发布了111 篇原创文章 · 获赞 0 · 访问量 2522

猜你喜欢

转载自blog.csdn.net/qq_42024433/article/details/105010909
今日推荐