深海 深海
首页
  • 随手笔录
  • 电影
  • 音乐
  • 书籍
汇总
面试
  • 开发工具
  • VScode插件
  • Git
  • Mac时代
  • 前端工具
  • Chrome
  • HTML
  • CSS
  • Javascript
  • Typescript
  • Axios
  • 框架

    • Vue
    • uni-app
  • Nginx
  • Linuk
事例
关于

深海

人生如逆旅,我亦是行人
首页
  • 随手笔录
  • 电影
  • 音乐
  • 书籍
汇总
面试
  • 开发工具
  • VScode插件
  • Git
  • Mac时代
  • 前端工具
  • Chrome
  • HTML
  • CSS
  • Javascript
  • Typescript
  • Axios
  • 框架

    • Vue
    • uni-app
  • Nginx
  • Linuk
事例
关于
  • 网站部署
  • Nginx
    • 安装
      • 1.更新软件包列表
      • 2.安装 Nginx
      • 3.验证 Nginx 是否安装成功
      • 4.管理 Nginx 服务
      • systemctl 方式(推荐)
      • service 方式
      • 命令方式
  • 运维
深海
2025-02-08
目录

Nginx

# 安装

在 Ubuntu 系统上安装 Nginx 可以按照以下步骤进行:

# 1.更新软件包列表

在安装新软件之前,建议先更新系统的软件包列表,以确保使用的是最新的软件源信息。打开终端,执行以下命令:

sudo apt update
1

该命令会连接到 Ubuntu 软件源服务器,获取最新的软件包信息并更新本地的软件包列表。

# 2.安装 Nginx

sudo apt install nginx
1

执行此命令后,系统会询问是否继续安装,输入 Y 并按回车键确认。安装过程可能需要一些时间,具体取决于网络速度和服务器性能。

# 3.验证 Nginx 是否安装成功

检查 Nginx 服务状态
sudo systemctl status nginx
1

如果 Nginx 已成功启动,你会看到类似如下的输出:

nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-02-07 17:57:41 CST; 23h ago
       Docs: man:nginx(8)
    Process: 239772 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCES>
    Process: 239774 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 239775 (nginx)
      Tasks: 3 (limit: 1942)
     Memory: 8.3M (peak: 12.1M)
        CPU: 2.514s
     CGroup: /system.slice/nginx.service
             ├─239775 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─239776 "nginx: worker process"
             └─239777 "nginx: worker process"

Feb 07 17:57:41 iZ2zeakq6j4oz72ayqg9glZ systemd[1]: Starting nginx.service - A high performance web server and a reve>
Feb 07 17:57:41 iZ2zeakq6j4oz72ayqg9glZ systemd[1]: Started nginx.service - A high performance web server and a rever>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

其中 Active: active (running) 表示 Nginx 服务正在运行。

通过浏览器访问

打开浏览器,在地址栏输入服务器的公网 IP 地址。如果看到 Nginx 的欢迎页面,说明 Nginx 已经成功安装并可以正常工作。

# 4.管理 Nginx 服务

# systemctl 方式(推荐)

# 启动
systemctl start nginx
# 停止
systemctl stop nginx
# 重启
systemctl restart nginx
# 重新加载配置
systemctl reload nginx
# 查看状态
systemctl status nginx
# 设置开机启动
systemctl enable nginx
# 禁用开机启动
systemctl disable nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# service 方式

# 启动
service nginx start
# 停止
service nginx stop
# 重启
service nginx restart
# 重新加载配置
service nginx reload
# 查看状态
service nginx status
1
2
3
4
5
6
7
8
9
10

# 命令方式

# 启动
nginx
# 停止
nginx -s stop    # 快速停止
nginx -s quit    # 优雅停止
# 重新加载配置
nginx -s reload
# 重新打开日志文件
nginx -s reopen
1
2
3
4
5
6
7
8
9
上次更新: 2025/02/11, 18:43:07
网站部署

← 网站部署

最近更新
01
TypeScript是什么
06-15
02
项目搭建
05-21
03
Prettier
02-27
更多文章>
Theme by Vdoing | Copyright © 2022-2025 京ICP备2020044002号-4 京公网安备11010502056618号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式