重识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

相关文章

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

Nginx中配置使用非默认80端口进行服务的完整指南

《Nginx中配置使用非默认80端口进行服务的完整指南》在实际生产环境中,我们经常需要将Nginx配置在其他端口上运行,本文将详细介绍如何在Nginx中配置使用非默认端口进行服务,希望对大家有所帮助... 目录一、为什么需要使用非默认端口二、配置Nginx使用非默认端口的基本方法2.1 修改listen指令

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

Nginx添加内置模块过程

《Nginx添加内置模块过程》文章指导如何检查并添加Nginx的with-http_gzip_static模块:确认该模块未默认安装后,需下载同版本源码重新编译,备份替换原有二进制文件,最后重启服务验... 目录1、查看Nginx已编辑的模块2、Nginx官网查看内置模块3、停止Nginx服务4、Nginx

通过配置nginx访问服务器静态资源的过程

《通过配置nginx访问服务器静态资源的过程》文章介绍了图片存储路径设置、Nginx服务器配置及通过http://192.168.206.170:8007/a.png访问图片的方法,涵盖图片管理与服务... 目录1.图片存储路径2.nginx配置3.访问图片方式总结1.图片存储路径2.nginx配置

Nginx禁用TLSv1.0 1.1改为TLSv1.2 1.3的操作方法

《Nginx禁用TLSv1.01.1改为TLSv1.21.3的操作方法》使用MozillaSSL配置工具生成配置,修改nginx.conf的ssl_protocols和ssl_ciphers,通... 目录方法一:方法二:使用 MoziChina编程lla 提供的 在线生成SSL配置工具,根据自己的环境填充对应的

nginx配置错误日志的实现步骤

《nginx配置错误日志的实现步骤》配置nginx代理过程中,如果出现错误,需要看日志,可以把nginx日志配置出来,以便快速定位日志问题,下面就来介绍一下nginx配置错误日志的实现步骤,感兴趣的可... 目录前言nginx配置错误日志总结前言在配置nginx代理过程中,如果出现错误,需要看日志,可以把

Nginx进行平滑升级的实战指南(不中断服务版本更新)

《Nginx进行平滑升级的实战指南(不中断服务版本更新)》Nginx的平滑升级(也称为热升级)是一种在不停止服务的情况下更新Nginx版本或添加模块的方法,这种升级方式确保了服务的高可用性,避免了因升... 目录一.下载并编译新版Nginx1.下载解压2.编译二.替换可执行文件,并平滑升级1.替换可执行文件

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

Nginx安全防护的多种方法

《Nginx安全防护的多种方法》在生产环境中,需要隐藏Nginx的版本号,以避免泄漏Nginx的版本,使攻击者不能针对特定版本进行攻击,下面就来介绍一下Nginx安全防护的方法,感兴趣的可以了解一下... 目录核心安全配置1.编译安装 Nginx2.隐藏版本号3.限制危险请求方法4.请求限制(CC攻击防御)