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

前言

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

我们为 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.04focalx86_64, aarch64/arm64, s390x
22.04jammyx86_64, aarch64/arm64, s390x
22.10kineticx86_64, aarch64/arm64
23.04lunarx86_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 serverLoaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2024-05-11 10:38:03 CST; 4min 2s agoDocs: 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.0MCGroup: /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 serverLoaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2024-05-11 10:44:40 CST; 11s agoDocs: 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.1MCGroup: /system.slice/nginx.service...

停止 Nginx

   sudo systemctl stop nginx

停止后查看状态:

$ sudo systemctl status nginx
○ nginx.service - A high performance web server and a reverse proxy serverLoaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)Active: inactive (dead) since Sat 2024-05-11 10:43:42 CST; 2s agoDocs: 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/19624.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

23种软件设计模式——工厂模式

工厂模式 工厂模式&#xff08;Factory Pattern&#xff09;是 Java 中最常用的设计模式之一&#xff0c;它提供了一种创建对象的方式&#xff0c;使得创建对象的过程与使用对象的过程分离。 工厂模式提供了一种创建对象的方式&#xff0c;而无需指定要创建的具体类。 通过使…

关于linux查询free内存消耗命令

1、查询docker的镜像消耗free总和 docker stats --no-stream --format "table {{.Container}}\t{{.Name}}\t{{.MemUsage}}" | awk NR1 { print; next } {split($3, a, "/");mem a[1];if (mem ~ /MiB/) {mem_mb substr(mem, 1, length(mem)-3);} else…

身份认证与口令攻击

身份认证与口令攻击 身份认证身份认证的五种方式口令认证静态口令动态口令(一次性口令)动态口令分类 密码学认证一次性口令认证S/KEY协议改进的S/KEY协议 其于共享密钥的认证 口令行为规律和口令猜测口令规律口令猜测 口令破解操作系统口令破解Windows密码存储机制Windows密码破…

二分查找与模板

二分查找也称折半查找&#xff08;Binary Search&#xff09;&#xff0c;它是一种效率较高的查找方法。但是&#xff0c;折半查找要求线性表必须采用顺序存储结构&#xff0c;而且表中元素按关键字有序排列 模板如下 bool check(int x) // 检查x是否满足某种性质//模板一&am…

2024新版二开微信发卡小程序源码卡密系统流支持量主

2024新版二开微信发卡小程序源码卡密系统流支持量主。裂变扩展多种领取模式二次开发的发卡小程序源码&#xff0c;其后台采用PHP编写&#xff0c;支持用户通过付费购卡或者观看视频广告领取卡密&#xff0c;该小程序还支持流量主&#xff0c;因为功能需要&#xff0c;我就进行了…

WinSW使用说明

WinSW使用说明 Windows系统下部署多个java程序 场景&#xff1a; 多个java的jar程序&#xff0c;通常来说一个程序使用一个cmd窗口&#xff0c;通过java -jar xxx.jar 命令来运行。这样如果程序多了打开cmd窗口也就多了。 解决&#xff1a; 通过使用WinSW程序&#xff0c;把ja…

VisualSVN Server/TortoiseSVN更改端口号

文章目录 概述VisualSVN Server端更改端口号TortoiseSVN客户端更改远程仓库地址 概述 Subversion&#xff08;SVN&#xff09;是常用的版本管理系统之一。部署在服务器上的SVN Server端通常会在端口号80&#xff0c;或者端口号443上提供服务。其中80是HTTP访问方式的默认端口。…

AndroidFlutter混合开发

为什么要有混合开发 我们知道&#xff0c;Flutter是可以做跨平台开发的&#xff0c;即一份Flutter的Dart代码&#xff0c;可以编译到多个平台上运行。这么做的好处就是&#xff0c;在不降低多少性能的情况下&#xff0c;尽最大可能的节省开发的时间成本&#xff0c;直接将开发…

带文字的短视频:成都鼎茂宏升文化传媒公司

带文字的短视频&#xff1a;视觉与文字的交织艺术 在信息爆炸的时代&#xff0c;短视频以其直观、生动的视觉呈现方式&#xff0c;迅速成为人们获取信息、娱乐休闲的重要渠道。然而&#xff0c;随着人们对内容深度和质量要求的提升&#xff0c;成都鼎茂宏升文化传媒公司单纯的…

项目4 移动电商运维自动化

项目引入 在一次移动电商系统发布更新上&#xff0c;由于我的不小心&#xff0c;错误地删除了生产服务器上的执行代码&#xff0c;导致整个移动电商系统页面都无法访问&#xff0c;最后花很长时间才恢复&#xff0c;这次事故给公司带来了不小的麻烦。 Philip组织整个运维团队进…

多屏多机同控!天途首发瑶光智控地面站

瑶光智控地面站全新发布&#xff01;高性能处理器&#xff0c;高亮三屏显示。内置天途云控系统&#xff0c;融合图传、控制、存储和数据处理等功能与一体&#xff0c;强大算力&#xff0c;高度集成无人机、无人船、无人车和机械狗等多种无人装备进行云控云算。 内置4G公网通讯模…

如何判断NP-hard问题

关键概念回顾 1、P类问题&#xff1a;可以在多项式时间内解决的问题。 2、NP类问题&#xff1a;解可以在多项式时间内验证的问题。NP类问题不一定能在多项式时间内解决&#xff0c;但其解一旦给出&#xff0c;可以在多项式时间内验证。 3、NP-hard问题&#xff1a;任意一个N…

LabVIEW调用外部DLL(动态链接库)

LabVIEW调用外部DLL&#xff08;动态链接库&#xff09; LabVIEW调用外部DLL&#xff08;动态链接库&#xff09;可以扩展其功能&#xff0c;使用外部库实现复杂计算、硬件控制等任务。通过调用节点&#xff08;Call Library Function Node&#xff09;配置DLL路径、函数名称和…

Django ORM入门指南:从概念到实践,掌握模型创建、迁移与视图操作

系列文章目录 Django入门全攻略&#xff1a;从零搭建你的第一个Web项目Django ORM入门指南&#xff1a;从概念到实践&#xff0c;掌握模型创建、迁移与视图操作[Django ORM实战&#xff1a;模型字段与元选项配置&#xff0c;以及链式过滤与QF查询详解]还在写0.0… 文章目录 系…

漫威Vision Pro沉浸式互动应用上线,引发行业内外对新型漫画模式的热烈讨论

近日,备受瞩目的漫威Vision Pro沉浸式互动应用正式与全球粉丝见面,这一创新尝试立即在行业内引起了广泛关注和热烈讨论。这款应用不仅融合了视频和轻游戏的元素,更被业内人士形象地称为“交互式沉浸式漫画”,为漫画爱好者带来全新的阅读体验。 在Vision Pro中,用户能够沉…

代码随想录算法训练营day39 | 738.单调递增的数字、968.监控二叉树

738.单调递增的数字 暴力解法超时 贪心解法&#xff1a;从后向前遍历&#xff0c;如果出现strNum[i - 1] > strNum[i]的情况&#xff08;非单调递增&#xff09;&#xff0c;让strNum[i - 1]--&#xff0c;然后strNum[i]给为9 class Solution:def monotoneIncreasingDigi…

道歉性质的《情况说明》应如何写,才能赢得对方的谅解?

道歉性质的《情况说明》应如何写&#xff0c;才能赢得对方的谅解&#xff1f; ——从“成都地铁被诬陷偷拍案”两涉事女的《情况说明》中想到了什么&#xff1f; 据九派新闻报道&#xff0c;在“成都地铁被诬陷偷拍案”中&#xff0c;近日两名当事女子罗某某和曾某某首次公开回…

网关(GateWay)- 快速使用

引入依赖 <!-- gateway --> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId> </dependency> 路由配置 server:port: 8088 spring:application:name: api-gatew…

零基础学会asp.net做网站/公众号/小程序之三:实战初体验(简单程序教学)

关注我&#xff0c;持续分享逻辑思维&管理思维&面试题&#xff1b; 可提供大厂面试辅导、及定制化求职/在职/管理/架构辅导&#xff1b; 博主在互联网大厂深耕近二十年&#xff0c;从一线码农做起&#xff0c;到人工智能公司副总裁。希望把过往经验总结出来&#xff0…

Flutter 中的 SliverFixedExtentList 小部件:全面指南

Flutter 中的 SliverFixedExtentList 小部件&#xff1a;全面指南 Flutter 是一个由 Google 开发的跨平台 UI 框架&#xff0c;它允许开发者使用 Dart 语言来构建高性能、美观的移动、Web 和桌面应用。在 Flutter 的丰富组件库中&#xff0c;SliverFixedExtentList 是一个高效…