重识Nginx - 04 Nginx常用命令行

2024-02-26 08:30
文章标签 nginx 常用命令 04 重识

本文主要是介绍重识Nginx - 04 Nginx常用命令行,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • Nginx命令行
    • 帮助命令
    • 使用指定的配置文件 -c
    • 指定配置指令 -g
    • 指定运行目录 -p
    • 发送信号 -s
    • 测试配置文件是否有语法错误 -t -T
    • 打印nginx的版本信息、编译信息等 -v -V

在这里插入图片描述

Nginx命令行

在这里插入图片描述

帮助命令

  -?,-h         : this help

[root@VM-0-7-centos sbin]# ./nginx  -h
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix][-e filename] [-c filename] [-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: /root/ng/artisan_ng/)-e filename   : set error log file (default: logs/error.log)-c filename   : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file[root@VM-0-7-centos sbin]# ./nginx  -?
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix][-e filename] [-c filename] [-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: /root/ng/artisan_ng/)-e filename   : set error log file (default: logs/error.log)-c filename   : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file[root@VM-0-7-centos sbin]#

在这里插入图片描述


使用指定的配置文件 -c


[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# cd ng/artisan_ng/
[root@VM-0-7-centos artisan_ng]# ll
total 36   当前目录 /root/ng/artisan_ng
drwx------ 2 nobody root 4096 Oct  2 09:56 client_body_temp
drwxr-xr-x 2 root   root 4096 Oct  2 09:55 conf
drwx------ 2 nobody root 4096 Oct  2 09:56 fastcgi_temp
drwxr-xr-x 2 root   root 4096 Sep 26 00:14 html
drwxr-xr-x 2 root   root 4096 Oct  2 09:56 logs
drwx------ 2 nobody root 4096 Oct  2 09:56 proxy_temp
drwxr-xr-x 2 root   root 4096 Sep 26 00:14 sbin
drwx------ 2 nobody root 4096 Oct  2 09:56 scgi_temp
drwx------ 2 nobody root 4096 Oct  2 09:56 uwsgi_temp
[root@VM-0-7-centos artisan_ng]#
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx  -c  ./conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C  (忽略这个错误,已经起来了ng)
[root@VM-0-7-centos artisan_ng]# cd sbin/
[root@VM-0-7-centos sbin]# ./nginx  -c /root/ng/artisan_ng/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C (忽略这个错误,已经起来了ng)
[root@VM-0-7-centos sbin]#

指定配置指令 -g

 -g directives : set global directives out of configuration file

指定运行目录 -p

-p prefix     : set prefix path 

[root@VM-0-7-centos artisan_ng]# pwd
/root/ng/artisan_ng
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx -p `pwd` -c ./conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
(忽略这个错误,已经起来了ng)

发送信号 -s

 -s signal     : send signal to a master process: stop, quit, reopen, reload
  • 立刻停止服务 stop
  • 优雅的停止服务 quit
  • 重载配置文件 reload
  • 重新开始记录日志文件 reopen

[root@VM-0-7-centos sbin]# ./nginx  -s stop
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root      447612  447331  0 12:22 pts/0    00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -s reload
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -s quit
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root      447738  447331  0 12:23 pts/0    00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root      447751       1  0 12:23 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody    447752  447751  0 12:23 ?        00:00:00 nginx: worker process
root      447758  447331  0 12:23 pts/0    00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#[root@VM-0-7-centos artisan_ng]# cd logs/
[root@VM-0-7-centos logs]# ll
total 16
-rw-r--r-- 1 nobody root 2001 Oct  2 12:23 access.log
-rw-r--r-- 1 nobody root 4658 Oct  2 12:23 error.log
-rw-r--r-- 1 root   root    7 Oct  2 12:23 nginx.pid
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]# mv access.log access.log_bak   改名   
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]# cd ../sbin/
[root@VM-0-7-centos sbin]# ./nginx  -s reopen  重新生成access 和 errorlog  , 没改名的话,不会新生成。 
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# cd ../logs/
[root@VM-0-7-centos logs]# ll
total 16
-rw-r--r-- 1 nobody root    0 Oct  2 12:24 access.log
-rw-r--r-- 1 nobody root 2001 Oct  2 12:23 access.log_bak
-rw-r--r-- 1 nobody root 4947 Oct  2 12:24 error.log
-rw-r--r-- 1 root   root    7 Oct  2 12:23 nginx.pid
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]#

在这里插入图片描述


测试配置文件是否有语法错误 -t -T

 -t            : test configuration and exit-T            : test configuration, dump it and exit

[root@VM-0-7-centos sbin]# ./nginx  -t
nginx: the configuration file /root/ng/artisan_ng/conf/nginx.conf syntax is ok
nginx: configuration file /root/ng/artisan_ng/conf/nginx.conf test is successful
[root@VM-0-7-centos sbin]# ./nginx -T
nginx: the configuration file /root/ng/artisan_ng/conf/nginx.conf syntax is ok
nginx: configuration file /root/ng/artisan_ng/conf/nginx.conf test is successful
# configuration file /root/ng/artisan_ng/conf/nginx.conf:#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {................
}# configuration file /root/ng/artisan_ng/conf/mime.types:types {text/html                                        html htm shtml;...............video/x-msvideo                                  avi;
}[root@VM-0-7-centos sbin]#

打印nginx的版本信息、编译信息等 -v -V

 -v            : show version and exit-V            : show version and configure options then exit
[root@VM-0-7-centos sbin]# ./nginx -v
nginx version: nginx/1.22.0
[root@VM-0-7-centos sbin]# ./nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/root/ng/artisan_ng
[root@VM-0-7-centos sbin]#

在这里插入图片描述

这篇关于重识Nginx - 04 Nginx常用命令行的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/748255

相关文章

Nginx中配置HTTP/2协议的详细指南

《Nginx中配置HTTP/2协议的详细指南》HTTP/2是HTTP协议的下一代版本,旨在提高性能、减少延迟并优化现代网络环境中的通信效率,本文将为大家介绍Nginx配置HTTP/2协议想详细步骤,需... 目录一、HTTP/2 协议概述1.HTTP/22. HTTP/2 的核心特性3. HTTP/2 的优

详解nginx 中location和 proxy_pass的匹配规则

《详解nginx中location和proxy_pass的匹配规则》location是Nginx中用来匹配客户端请求URI的指令,决定如何处理特定路径的请求,它定义了请求的路由规则,后续的配置(如... 目录location 的作用语法示例:location /www.chinasem.cntestproxy

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Nginx指令add_header和proxy_set_header的区别及说明

《Nginx指令add_header和proxy_set_header的区别及说明》:本文主要介绍Nginx指令add_header和proxy_set_header的区别及说明,具有很好的参考价... 目录Nginx指令add_header和proxy_set_header区别如何理解反向代理?proxy

jvm调优常用命令行工具详解

《jvm调优常用命令行工具详解》:本文主要介绍jvm调优常用命令行工具的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一 jinfo命令查看参数1.1 查看jvm参数二 jstack命令2.1 查看现场堆栈信息三 jstat 实时查看堆内存,gc情况3.1

Nginx配置location+rewrite实现隐性域名配置

《Nginx配置location+rewrite实现隐性域名配置》本文主要介绍了Nginx配置location+rewrite实现隐性域名配置,包括基于根目录、条件和反向代理+rewrite配置的隐性... 目录1、配置基于根目录的隐性域名(就是nginx反向代理)2、配置基于条件的隐性域名2.1、基于条件

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4

Nginx如何进行流量按比例转发

《Nginx如何进行流量按比例转发》Nginx可以借助split_clients指令或通过weight参数以及Lua脚本实现流量按比例转发,下面小编就为大家介绍一下两种方式具体的操作步骤吧... 目录方式一:借助split_clients指令1. 配置split_clients2. 配置后端服务器组3. 配

Nginx实现前端灰度发布

《Nginx实现前端灰度发布》灰度发布是一种重要的策略,它允许我们在不影响所有用户的情况下,逐步推出新功能或更新,通过灰度发布,我们可以测试新版本的稳定性和性能,下面就来介绍一下前端灰度发布的使用,感... 目录前言一、基于权重的流量分配二、基于 Cookie 的分流三、基于请求头的分流四、基于请求参数的分

一文详解Nginx的强缓存和协商缓存

《一文详解Nginx的强缓存和协商缓存》这篇文章主要为大家详细介绍了Nginx中强缓存和协商缓存的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、强缓存(Strong Cache)1. 定义2. 响应头3. Nginx 配置示例4. 行为5. 适用场景二、协商缓存(协