重识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访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

Nginx 重写与重定向配置方法

《Nginx重写与重定向配置方法》Nginx重写与重定向区别:重写修改路径(客户端无感知),重定向跳转新URL(客户端感知),try_files检查文件/目录存在性,return301直接返回永久重... 目录一.try_files指令二.return指令三.rewrite指令区分重写与重定向重写: 请求

Nginx 配置跨域的实现及常见问题解决

《Nginx配置跨域的实现及常见问题解决》本文主要介绍了Nginx配置跨域的实现及常见问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来... 目录1. 跨域1.1 同源策略1.2 跨域资源共享(CORS)2. Nginx 配置跨域的场景2.1

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

Windows的CMD窗口如何查看并杀死nginx进程

《Windows的CMD窗口如何查看并杀死nginx进程》:本文主要介绍Windows的CMD窗口如何查看并杀死nginx进程问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows的CMD窗口查看并杀死nginx进程开启nginx查看nginx进程停止nginx服务

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

NGINX 配置内网访问的实现步骤

《NGINX配置内网访问的实现步骤》本文主要介绍了NGINX配置内网访问的实现步骤,Nginx的geo模块限制域名访问权限,仅允许内网/办公室IP访问,具有一定的参考价值,感兴趣的可以了解一下... 目录需求1. geo 模块配置2. 访问控制判断3. 错误页面配置4. 一个完整的配置参考文档需求我们有一