首页 > 系统相关 >Nginx 实战-01-nginx ubuntu(windows WSL2) 安装笔记

Nginx 实战-01-nginx ubuntu(windows WSL2) 安装笔记

时间:2024-05-30 23:44:20浏览次数:15  
标签:process 01 windows sudo worker server nginx 手写

前言

大家好,我是老马。很高兴遇到你。

我们为 java 开发者实现了 java 版本的 nginx

https://github.com/houbb/nginx4j

如果你想知道 servlet 如何处理的,可以参考我的另一个项目:

手写从零实现简易版 tomcat minicat

手写 nginx 系列

如果你对 nginx 原理感兴趣,可以阅读:

从零手写实现 nginx-01-为什么不能有 java 版本的 nginx?

从零手写实现 nginx-02-nginx 的核心能力

从零手写实现 nginx-03-nginx 基于 Netty 实现

从零手写实现 nginx-04-基于 netty http 出入参优化处理

从零手写实现 nginx-05-MIME类型(Multipurpose Internet Mail Extensions,多用途互联网邮件扩展类型)

从零手写实现 nginx-06-文件夹自动索引

从零手写实现 nginx-07-大文件下载

从零手写实现 nginx-08-范围查询

从零手写实现 nginx-09-文件压缩

从零手写实现 nginx-10-sendfile 零拷贝

从零手写实现 nginx-11-file+range 合并

从零手写实现 nginx-12-keep-alive 连接复用

环境说明

本地 windows 使用 WSL

安装预构建的 Ubuntu 包

NGINX 为以下 Ubuntu 操作系统提供包:

版本 代号 支持的平台
20.04 focal x86_64, aarch64/arm64, s390x
22.04 jammy x86_64, aarch64/arm64, s390x
22.10 kinetic x86_64, aarch64/arm64
23.04 lunar x86_64, aarch64/arm64

可以从以下位置安装该包:

  • 默认的 Ubuntu 存储库。这是最快的方法,但通常提供的包已过时。

  • nginx.org 上的官方存储库。第一次必须设置 apt-get 存储库,但之后提供的包始终是最新的。

从 Ubuntu 存储库安装预构建的 Ubuntu 包

  1. 更新 Ubuntu 存储库信息:
sudo apt-get update
  1. 安装包:
sudo apt-get install nginx
  1. 验证安装:
sudo nginx -v

日志如下:

nginx version: nginx/1.18.0 (Ubuntu)

直接访问

$ curl http://localhost

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

常见操作命令

1. 查看状态

查看 Nginx 状态(检查是否正在运行):

sudo systemctl status nginx

如下:

 nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-05-11 10:38:03 CST; 4min 2s ago
       Docs: man:nginx(8)
    Process: 1537 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 1538 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 1645 (nginx)
      Tasks: 17 (limit: 9362)
     Memory: 18.0M
     CGroup: /system.slice/nginx.service
             ├─1645 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─1648 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1649 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1650 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1651 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1652 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1653 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1654 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1655 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1656 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1657 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1658 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1659 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1660 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1661 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─1662 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
             └─1663 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >

May 11 10:38:03 d systemd[1]: Starting A high performance web server and a reverse proxy server...

2. 启停 nginx

启动 Nginx

sudo systemctl start nginx

可以状态确认:

$ sudo systemctl status nginx

$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-05-11 10:44:40 CST; 11s ago
       Docs: man:nginx(8)
    Process: 3631 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3632 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 3633 (nginx)
      Tasks: 17 (limit: 9362)
     Memory: 14.1M
     CGroup: /system.slice/nginx.service
     ...

停止 Nginx

sudo systemctl stop nginx

停止后查看状态:

$ sudo systemctl status nginx
○ nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sat 2024-05-11 10:43:42 CST; 2s ago
       Docs: man:nginx(8)
    Process: 3396 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited,>
   Main PID: 1645 (code=exited, status=0/SUCCESS)

May 11 10:38:03 d systemd[1]: Starting A high performance web server and a reverse proxy server...
May 11 10:38:03 d systemd[1]: Started A high performance web server and a reverse proxy server.
May 11 10:43:42 d systemd[1]: Stopping A high performance web server and a reverse proxy server...
May 11 10:43:42 d systemd[1]: nginx.service: Deactivated successfully.
May 11 10:43:42 d systemd[1]: Stopped A high performance web server and a reverse proxy server.

重启

个人理解:重启=关闭+启动

sudo systemctl restart nginx

启动时自动运行 nginx

作用:可以让 ngix 是否在机器重启后服务自动运行。

  1. 使 Nginx 在启动时自动运行

    sudo systemctl enable nginx
    
  2. 禁止 Nginx 在启动时自动运行

    sudo systemctl disable nginx
    

标签:process,01,windows,sudo,worker,server,nginx,手写
From: https://www.cnblogs.com/houbbBlogs/p/18223488

相关文章

  • 你认识nginx吗,nginx是做什么的,nginx可以做什么 --1)nginx介绍
    ngNginx简介Nginx(发音同enginex)是一个异步框架的Web服务器,也可以用作反向代理,负载平衡器和HTTP缓存。该软件由 IgorSysoev 创建,并于2004年首次公开发布。同名公司成立于2011年,以提供支持。Nginx是一款免费的开源软件,根据类BSD许可证的条款发布。一大部分Web服务......
  • 你认识nginx吗,nginx是做什么的,nginx可以做什么 --2)nginx配置
    hello大家今天教大家如何用nginx实验tomcat的负载均衡,同理其他的也可以,如httpd等首先需要准备一个nginx和tomcat包,这里用到的是版本号为然后需要准备最少三台linux虚拟机,然后我们开始吧1.安装tomcat解包tarzxf/mnt/apache-tomcat-8.5.16.tar.gz-C/usr/src   ......
  • Windows下Qt使用dump定位崩溃位置(1)
    软件调试Windows下Qt使用dump定位崩溃位置(1)目录软件调试Windows下Qt使用dump定位崩溃位置(1)1、Qt崩溃定位方法2、什么是dump文件3、使用vs调试dmp4、下载Windows符号表5、下载Qt符号表6、主要代码7、源代码更多精彩内容......
  • N5_2013_07_Q3
    问题31ばん今から寝ます。家族に何と言いますか。现在要睡觉了。对家人说什么?1.おやすみなさい晚安2.こんばんは晚上好3.さようなら再见ねる(寝る)动睡觉かぞく(家族)名家人なんと言いますか疑怎么说2ばん時計がありません。時間が知りたいです。何と......
  • 认识Windows操作系统
    开机启动项在Windows系统中,开机启动项通常通过如下配置:注册表启动目录注册表按住WIN+R打开运行,输入regedit打开注册表编辑器用户启动项:\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run系统启动项:\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Cu......
  • P6342 [CCO2017] Vera 与道路建设 题解
    题目大意对于一个图w一共有v个点点的编号为1,2,...,v,对于点a与点b如果满足$a\tob$且$b\toa$使得每一条道路都只走过一次,那么我们称$a,b$为完美点对,当一个联通图只有$k$个完美点对时,称这个联通图为美丽公路网,要求求出一个美丽公路网......
  • Debug-013-el-loading中显示倒计时时间
    前言:            今天实现一个小小的优化,业务上是后端需要从设备上拿数据,所以前端需要不断调用一个查询接口,直到后端数据获取完毕,前后端根据一个ending字段为true判断停止调用查询接口。由于这个查询时间比较久,所以需要一个laoding效果。优化:前端除了根据后......
  • 01--nginx基础
    前言:本文用来整理一下nginx的用法,应该是本人中间件专栏的第一篇文章,这里开始概念和实操将会同样重要,面试时基本概念的理解非常重要,深有体会,不会再让概念成为压死骆驼的稻草。1、nginx简介Nginx(enginex)是一个高性能的HTTP(解决C10k的问题)和反向代理服务器,也是一个IMAP/......
  • Nginx网站服务
    目录1.Nginx服务基础(1)Nginx与Apache的区别(2)编译安装Nginx服务2.Nginx虚拟主机Nginx是一款高性能、轻量级Web服务软件;稳定性高;系统资源消耗低;对HTTP并发连接的处理能力高(单台物理服务器可支持30000~50000个并发请求)。1.Nginx服务基础(1)Nginx与Apache的区别Nginx采用异步非阻塞......
  • Windows 系统下使用 XCOPY 复制 文件夹
    Windows系统下使用XCOPY复制文件夹@echooffxcopy/E/C/I/F/G/H/R/K/O/X/Y/B\\192.168.88.84\c$\dataE:\datapause1:这里的/E/H/K/O/X/B代表完整复制(包括空文件夹、隐藏文件、文件属性、文件所有权和ACL信息、审核设置、也复制链接目标)2:这里的/C/I/G/R......