如何启动、停止或重启Nginx?

当我们安装好Nginx后,需要学会对其进行启动、停止、重启等操作。本篇文章将详细介绍 Nginx 的启动、停止或重启等指令及操作步骤。

启动Nginx

以下是启动 Nginx 的指令及步骤:

  1. 打开终端,进入到 Nginx 的安装目录

sh
cd /usr/local/nginx/sbin/

注:如果您的 Nginx 安装在其他目录,可以根据自己的情况进入相应的目录。

  1. 执行启动命令

sh
sudo ./nginx

或者

sh
sudo nginx

当您看到类似以下输出时,表示 Nginx 已经成功启动:

nginx: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2021/06/16 10:33:10 [notice] 17951#0: nginx/1.21.0
2021/06/16 10:33:10 [notice] 17951#0: built by gcc 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04.1)
2021/06/16 10:33:10 [notice] 17951#0: OS: Linux 4.15.0-128-generic
2021/06/16 10:33:10 [notice] 17951#0: getrlimit(RLIMIT_NOFILE): 1024:4096
2021/06/16 10:33:10 [notice] 17951#0: start worker processes
2021/06/16 10:33:10 [notice] 17951#0: start worker process 17953

注:上面的输出信息可能因 Nginx 的版本不同而有所不同。

停止Nginx

以下是停止 Nginx 的指令及步骤:

  1. 进入 Nginx 的安装目录

sh
cd /usr/local/nginx/sbin/

  1. 执行停止命令

sh
sudo ./nginx -s stop

当您看到类似以下输出时,表示 Nginx 已经停止:

nginx: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

注:上面的输出信息可能因 Nginx 的版本不同而有所不同。

重启Nginx

以下是重启 Nginx 的指令及步骤:

  1. 进入 Nginx 的安装目录

sh
cd /usr/local/nginx/sbin/

  1. 执行重启命令

sh
sudo ./nginx -s reload

当您看到类似以下输出时,表示 Nginx 已经重启:

nginx: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
nginx: [notice] 17953#0: signal process started
nginx: [notice] 17953#0: gracefully shutting down
nginx: [notice] 17953#0: exiting
nginx: [notice] 17953#0: exit
nginx: [notice] 18061#0: nginx/1.21.0
nginx: [notice] 18061#0: built by gcc 8.4.0 (Ubuntu 8.4.0-1ubuntu1~18.04.1)
nginx: [notice] 18061#0: OS: Linux 4.15.0-128-generic
nginx: [notice] 18061#0: getrlimit(RLIMIT_NOFILE): 1024:4096
nginx: [notice] 18061#0: start worker processes
nginx: [notice] 18061#0: start worker process 18065
nginx: [notice] 18061#0: signal process started

注:上面的输出信息可能因 Nginx 的版本不同而有所不同。

除此之外,您还可以通过以下方式对 Nginx 进行操作:

# 测试配置文件是否正常
sudo ./nginx -t

# 以指定的配置文件启动
sudo ./nginx -c /usr/local/nginx/conf/nginx.conf

# 以指定的配置文件测试
sudo ./nginx -c /usr/local/nginx/conf/nginx.conf -t

示例:

sudo nginx -t -c /etc/nginx/nginx.conf

这条命令用来测试 Nginx 的配置文件是否出现错误。

sudo nginx -s stop -c /etc/nginx/nginx.conf

这条命令用来停止对应配置文件的 Nginx。

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:如何启动、停止或重启Nginx? - Python技术站

(0)
上一篇 2023年4月19日
下一篇 2023年4月19日

相关文章

  • nginx 配置 vue (history模式) 项目

    vue中有两种模式 history模式(访问地址中包含 /#/ ),有的场景下(例如官网),访问地址出现该路径会比较难看,需要优化,需要切换到另外一种模式,但是nginx需要配置一下,不然刷新页面会出现404 server {listen 8075;server_name localhost;root /home/vol1/zenuo_html;locati…

    Nginx 2023年4月10日
    00
  • 安装nginx环境(含lua)时遇到报错ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory的解决

    下面是安装nginx+lua环境时使用的相关模块及版本,ngx_devel_kit和lua-nginx-module模块用的都是github上最新的模块.并进行了LuaJIT的安装。    #Install nginx by 2019-12-12 yum -y install gcc gcc-c++ autoconf automake yum -y inst…

    Nginx 2023年4月13日
    00
  • nginx部署vue项目的详细图文教程

    下面是“nginx部署vue项目的详细图文教程”的完整攻略。 环境准备 一台服务器,推荐使用 Ubuntu 系统 安装 Nginx sudo apt-get install nginx 安装 Node.js sudo apt-get install nodejs 安装 npm sudo apt-get install npm 创建 Vue 项目 首先,我们需…

    Nginx 2023年5月16日
    00
  • nginx配置与常见错误解决方法

    1、下载:到官网下载nginx稳定版,解压到e盘根目录;到官网下载php非安装版,解压到e盘根目录。2、配置:打开nginx.conf,修改相关位置如下,location / {            root   html; #网站根目录            index  index.html index.htm index.php;          …

    Nginx 2023年4月12日
    00
  • nginx常用代理配置

    因为业务系统需求,需要对web服务作nginx代理,在不断的尝试过程中,简单总结了一下常见的nginx代理配置。 1. 最简反向代理配置 在http节点下,使用upstream配置服务地址,使用server的location配置代理映射。 upstream my_server { server 10.0.0.2:8080; keepalive 2000; }…

    Nginx 2023年4月13日
    00
  • 4、请解释Nginx服务器上的Master和Worker进程分别是什么?

    Master进程:master进程负责管理worker进程,并负责读取配置文件和判断文件语法的工作;是主进程,且只有一个。 Worker进程:worker进程有多个,它负责处理请求;worker的进程数量由管理员自己定义;    worker_processes 1;意思是nginx启动后,worker进程只有一个,如果想有多个,可以自己改动,但不能超过机器…

    Nginx 2023年4月12日
    00
  • Nginx+Tomcat+Memcached部署

    通常我们企业也会使用JSP来发布动态网页,那么我们怎样将他们很好的整合,使用一台http服务器对外发布呢?这个时候我们就可以使用Nginx作为前端服务器来对Tomcat进行调度和负载,同时基于jsp的动态特征,我们将引入memcached来保持网页在链接过程中的session同步问题。 主机角色:node1:192.168.20.101        tom…

    Nginx 2023年4月13日
    00
  • nginx:windows下按天切割日志

    利用 BAT脚本和任务计划程序来完成。 1.BAT @echo on set nginx=d:\logs\nginx set history=d:\logs\nginx\history md %history% net stop nginx set “Ymd=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time…

    2023年4月9日
    00
合作推广
合作推广
分享本页
返回顶部