NGINX源码安装

文章目录

  • NGINX源码安装
    • 安装依赖包
    • 获取源码
      • NGINX官方网站
      • 各个目录的用途
    • 编译安装
    • 安装结束后的文件
    • 设置为服务

NGINX源码安装

安装依赖包

root执行

yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

这些包是用于开发和构建软件的一些常见库和工具。
1.gcc: GNU Compiler Collection 的缩写,是一个用于编译源代码的编译器套件。它可以将高级编程语言(如C、C++等)编译为目标机器的可执行二进制代码。NGINX就是用C写的,要编译成二进制的文件。
2. gcc-c++: 这是 GCC 编译器的 C++ 支持,它允许您编译和构建使用 C++ 编程语言编写的软件。NGINX虽然是C语言写的,但不可避免的使用到C++的一些特性。
3. make: 是一个自动化构建工具,用于处理源代码和构建过程。通过 make 命令,您可以根据预定义的规则和指令自动执行编译、链接和安装等任务。
4. libtool: 是一个用于处理共享库的工具,它允许开发者在不同的操作系统上创建和使用共享库。
5. zlib 和 zlib-devel: zlib 是一个用于数据压缩和解压缩的库,广泛用于许多软件中以减小数据的存储空间和传输带宽。zlib-devel 包含用于开发和编译 zlib 相关程序的头文件和库文件。
6. openssl 和 openssl-devel: OpenSSL 是一个开源的加密库,提供了许多加密和安全相关的功能,如 SSL/TLS 协议、数字证书管理等。openssl-devel 包含了用于开发和编译使用 OpenSSL 的程序的头文件和库文件。
7. pcre 和 pcre-devel: PCRE(Perl Compatible Regular Expressions)是一个正则表达式库,用于处理文本匹配和替换操作。pcre-devel 包含用于开发和编译使用 PCRE 的程序的头文件和库文件。

以上软件是必要的软件包,如果不安装以上包可能会存在某些配置或功能不能使用的情况。

获取源码

NGINX官方网站

NGINX有两个版本,社区版和商业版
我们使用社区版进行研究,一般情况下社区版是能满足我们的需求的

NGINX社区版又分mainline版本和stable版本, 想尝鲜用mainline,想稳定用stable,一般我们线上选择stable版本,即中间位数是偶数的版本。
在这里插入图片描述### 获取步骤

# 创建升级的文件夹
mkdir -p /opt/darren/upgrade
cd /opt/darren/upgrade
# 获取安装的源码
wget -c https://nginx.org/download/nginx-1.24.0.tar.gz
# 解压包
tar -zxvf nginx-1.24.0.tar.gz
cd /opt/darren/upgrade/nginx-1.24.0

各个目录的用途

[root@WDQCVM nginx-1.24.0]# ll
total 816
drwxr-xr-x 6 wdq  wdq     326 Aug 14 18:39 auto
-rw-r--r-- 1 wdq  wdq  323312 Apr 11 09:45 CHANGES
-rw-r--r-- 1 wdq  wdq  494234 Apr 11 09:45 CHANGES.ru
drwxr-xr-x 2 wdq  wdq     168 Aug 14 18:39 conf
-rwxr-xr-x 1 wdq  wdq    2611 Apr 11 09:45 configure
drwxr-xr-x 4 wdq  wdq      72 Aug 14 18:39 contrib
drwxr-xr-x 2 wdq  wdq      40 Aug 14 18:39 html
-rw-r--r-- 1 wdq  wdq    1397 Apr 11 09:45 LICENSE
-rw-r--r-- 1 root root    458 Aug 14 18:53 Makefile
drwxr-xr-x 2 wdq  wdq      21 Aug 14 18:39 man
drwxr-xr-x 3 root root    125 Aug 14 18:53 objs
-rw-r--r-- 1 wdq  wdq      49 Apr 11 09:45 README
drwxr-xr-x 9 wdq  wdq      91 Aug 14 18:39 src
[root@WDQCVM nginx-1.24.0]# 
  • auto目录,编译、支持哪些模块、当前系统有哪些特性给NGINX使用
  • CHANGES 提供了哪些特性,和BugFix,.ru是因为NGINX之父是俄罗斯人
  • conf 示例文件
  • configure编译文件
  • contrib 该文件中是一些对NGINX支持高亮显示的文件,这里的内容拷贝到VIM中可以高亮
  • html 提供了500 和index文件
  • man NGINX的帮助文件
  • src NGINX源代码
  • objs 是生成中间文件的目录
    • 其中有个ngx_modules.c的文件,这里记录所有进去的NGINX模块

编译安装

查看configure支持的参数
这里有很多参数,如果不需要变动则只需指定--prefix指定编译后的路径即可
还有带有--with-……这种默认是不会编译进NGINX的,相反 --without-……这种默认是编译进NGINX中的

[root@WDQCVM nginx-1.24.0]# ./configure --help--help                             print this message--prefix=PATH                      set installation prefix--sbin-path=PATH                   set nginx binary pathname--modules-path=PATH                set modules path--conf-path=PATH                   set nginx.conf pathname--error-log-path=PATH              set error log pathname--pid-path=PATH                    set nginx.pid pathname--lock-path=PATH                   set nginx.lock pathname--user=USER                        set non-privileged user forworker processes--group=GROUP                      set non-privileged group forworker processes--build=NAME                       set build name--builddir=DIR                     set build directory--with-select_module               enable select module--without-select_module            disable select module--with-poll_module                 enable poll module--without-poll_module              disable poll module--with-threads                     enable thread pool support--with-file-aio                    enable file AIO support--with-http_ssl_module             enable ngx_http_ssl_module
……--with-http_stub_status_module     enable ngx_http_stub_status_module--without-http_charset_module      disable ngx_http_charset_module--without-http_gzip_module         disable ngx_http_gzip_module
……--without-http_upstream_zone_moduledisable ngx_http_upstream_zone_module--with-http_perl_module            enable ngx_http_perl_module
……--with-perl=PATH                   set perl binary pathname--http-log-path=PATH               set http access log pathname--http-client-body-temp-path=PATH  set path to storehttp client request body temporary files--http-proxy-temp-path=PATH        set path to storehttp proxy temporary files--http-fastcgi-temp-path=PATH      set path to storehttp fastcgi temporary files--http-uwsgi-temp-path=PATH        set path to storehttp uwsgi temporary files--http-scgi-temp-path=PATH         set path to storehttp scgi temporary files--without-http                     disable HTTP server--without-http-cache               disable HTTP cache--with-mail                        enable POP3/IMAP4/SMTP proxy module……--with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module--without-stream_limit_conn_module disable ngx_stream_limit_conn_module……--without-stream_upstream_zone_moduledisable ngx_stream_upstream_zone_module--with-google_perftools_module     enable ngx_google_perftools_module
……--with-openssl-opt=OPTIONS         set additional build options for OpenSSL--with-debug                       enable debug logging[root@WDQCVM nginx-1.24.0]# 

编译

cd /opt/darren/upgrade/nginx-1.24.0
mkdir -p /opt/darren/dev/
./configure --prefix=/opt/darren/dev/nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-http_gzip_static_module --with-pcre  
make
make install
  • ./configure:这是运行 NGINX 配置脚本的命令。
  • --prefix=/opt/darren/dev/nginx:指定 NGINX 的安装路径为 /opt/darren/dev/nginx,这是 NGINX 被安装到的主目录。
  • --with-http_ssl_module:启用 HTTP SSL 模块,允许 NGINX 支持通过 HTTPS 提供加密的安全连接。
  • --with-http_stub_status_module:启用 HTTP Stub Status 模块,该模块提供了一个简单的状态页面,用于监控 NGINX 的运行状态和统计信息。
  • --with-stream:启用 Stream 模块,使 NGINX 能够处理基于 TCP 或 UDP 的流量。
  • --with-http_gzip_static_module:启用 HTTP Gzip Static 模块,该模块允许 NGINX 在服务器端对静态文件进行 Gzip 压缩,以提高传输效率。
  • --with-pcre:启用 PCRE(Perl Compatible Regular Expressions)模块,该模块用于支持正则表达式,通常用于 URI 路径匹配等。
  • make 和 make install 来执行完成安装操作
    在编译过程中有很多信息,这些信息只要没有报错信息即可,如果有报错信息则需要排查错误后再编译安装。

安装结束后的文件

编译的文件是

[root@WDQCVM nginx]# cd /opt/darren/dev/nginx
[root@WDQCVM nginx]# ll
total 0
drwxr-xr-x 2 root root 333 Aug 14 19:30 conf
drwxr-xr-x 2 root root  40 Aug 14 19:30 html
drwxr-xr-x 2 root root   6 Aug 14 19:30 logs
drwxr-xr-x 2 root root  19 Aug 14 19:30 sbin
[root@WDQCVM nginx]#
  • conf配置文件
  • html 静态页面
  • logs存放日志的目录
  • sbin二进制文件存放的地方

设置为服务

服务启动

# 测试语法是否有问题
[root@WDQCVM sbin]# /opt/darren/dev/nginx/sbin/nginx -t -c /opt/darren/dev/nginx/conf/nginx.conf
nginx: the configuration file /opt/darren/dev/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/darren/dev/nginx/conf/nginx.conf test is successful
# 启动
[root@WDQCVM sbin]# /opt/darren/dev/nginx/sbin/nginx -c /opt/darren/dev/nginx/conf/nginx.conf
[root@WDQCVM sbin]# ps -ef|grep nginx
root      6677     1  0 19:35 ?        00:00:00 nginx: master process /opt/darren/dev/nginx/sbin/nginx -c /opt/darren/dev/nginx/conf/nginx.conf
nobody    6678  6677  0 19:35 ?        00:00:00 nginx: worker process
root      6680  1148  0 19:35 pts/0    00:00:00 grep --color=auto nginx
[root@WDQCVM sbin]# 

将NGINX设置为服务

[root@WDQCVM sbin]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network. target remote-fs.target nss -lookup. target[Service]
Type=forking
PIDFile=/opt/darren/dev/nginx/logs/nginx.pid
ExecStartPre=/opt/darren/dev/nginx/sbin/nginx -t -c /opt/darren/dev/nginx/conf/nginx.conf
ExecStart=/opt/darren/dev/nginx/sbin/nginx -c /opt/darren/dev/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target

服务重载

systemctl daemon-reload

以服务的方式启动

[root@WDQCVM sbin]# systemctl start nginx
[root@WDQCVM sbin]# systemctl status nginx
● nginx.service - nginx - high performance web serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)Active: active (running) since Mon 2023-08-14 19:40:15 CST; 1s agoDocs: https://nginx.org/en/docs/Process: 6737 ExecStart=/opt/darren/dev/nginx/sbin/nginx -c /opt/darren/dev/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)Process: 6736 ExecStartPre=/opt/darren/dev/nginx/sbin/nginx -t -c /opt/darren/dev/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)Main PID: 6739 (nginx)CGroup: /system.slice/nginx.service├─6739 nginx: master process /opt/darren/dev/nginx/sbin/nginx -c /opt/darren/dev/nginx/conf/nginx.conf└─6740 nginx: worker processAug 14 19:40:15 WDQCVM systemd[1]: [/usr/lib/systemd/system/nginx.service:6] Failed to add dependency on -lookup., ignoring: Invalid argument
Aug 14 19:40:15 WDQCVM systemd[1]: [/usr/lib/systemd/system/nginx.service:6] Failed to add dependency on target, ignoring: Invalid argument
Aug 14 19:40:15 WDQCVM systemd[1]: Starting nginx - high performance web server...
Aug 14 19:40:15 WDQCVM nginx[6736]: nginx: the configuration file /opt/darren/dev/nginx/conf/nginx.conf syntax is ok
Aug 14 19:40:15 WDQCVM nginx[6736]: nginx: configuration file /opt/darren/dev/nginx/conf/nginx.conf test is successful
Aug 14 19:40:15 WDQCVM systemd[1]: Started nginx - high performance web server.
[root@WDQCVM sbin]# 

设置为开机启动

[root@WDQCVM sbin]# systemctl  enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@WDQCVM sbin]

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

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

相关文章

R语言生存分析算法的简单组合

library(survival) library(randomForestSRC)# 生成模拟数据 set.seed(123) n <- 200 time <- rexp(n, rate 0.1) status <- rbinom(n, size 1, prob 0.7) var1 <- rnorm(n) var2 <- rnorm(n) var3 <- rnorm(n) data1 <- data.frame(time time, statu…

C语言案例 分数列求和-11

题目&#xff1a;有一分数列&#xff1a;2 / 1,3 / 2,5 / 3,8 / 5,13 / 8,21 / 13 …求出这个数列的前20项之和。 程序分析 这是一个典型的分数列数学逻辑题&#xff0c;考究这类题目是需要从已知的条件中找到它们的分布规律 我们把前6荐的分子与分母分别排列出来&#xff0c;…

ClickHouse(十八):Clickhouse Integration系列表引擎

进入正文前&#xff0c;感谢宝子们订阅专题、点赞、评论、收藏&#xff01;关注IT贫道&#xff0c;获取高质量博客内容&#xff01; &#x1f3e1;个人主页&#xff1a;含各种IT体系技术&#xff0c;IT贫道_Apache Doris,大数据OLAP体系技术栈,Kerberos安全认证-CSDN博客 &…

谷粒商城第十一天-品牌管理中关联分类

目录 一、总述 二、前端部分 1. 调整查询调用 2. 关联分类 三、后端部分 四、总结 一、总述 之前是在商品的分类管理中直接使用的若依的逆向代码 有下面的几个问题&#xff1a; 1. 表格上面的参数填写之后&#xff0c;都是按照完全匹配进行搜索&#xff0c;没有模糊匹配…

Datawhale Django后端开发入门Task01 Vscode配置环境

首先呢放一张运行成功的截图纪念一下&#xff0c;感谢众多小伙伴的帮助呀&#xff0c;之前没有配置这方面的经验 &#xff0c;但还是一步一步配置成功了&#xff0c;所以在此以一个纯小白的经验分享如何配置成功。 1.选择要建立项目的文件夹&#xff0c;打开文件找到目标文件夹…

菜单和内容滚动的联动原理及代码

之前写代码有个需求&#xff1a;左侧是一个菜单&#xff0c;右边是内容&#xff0c;点击左侧菜单右边内容滚动到对应位置&#xff0c;右边内容滚动到某位置时&#xff0c;左侧菜单也会选中对应的菜单项。UI如下&#xff1a;这是大多网站的移动端都会有的需求。 解决方案一&…

三分钟完美解决你的C盘内存过大爆红

一、清理回收站 二、清理桌面 建议一 不要在桌面放太多图标或者文件会占用过多的内存,可以放到其他盘建议二、 将位置移动到别的盘 三、手动删除下载文件与缓存文件 日常使用中会通过Windows下载各种文件资料到电脑中&#xff0c;它默认也是直接下载在C盘中的。如果我们在以…

机器视觉项目流程和学习方法

机器视觉项目流程&#xff1a; 00001. 需求分析和方案建立 00002. 算法流程规划和业务逻辑设计 00003. 模块化编程和集成化实现 00004. 调试和优化&#xff0c;交付客户及文档 学习机器视觉的方法&#xff1a; 00001. 实战学习&#xff0c;结合项目经验教训 00002. 学习…

力扣 474. 一和零

题目来源&#xff1a;https://leetcode.cn/problems/ones-and-zeroes/description/ C题解&#xff1a;本题其实是01背包问题&#xff01;只不过这个背包有两个维度&#xff0c;一个是m 一个是n&#xff0c;而不同长度的字符串就是不同大小的待装物品。动规五部曲&#xff1a; …

【网络】传输层——TCP(滑动窗口流量控制拥塞控制延迟应答捎带应答)

&#x1f431;作者&#xff1a;一只大喵咪1201 &#x1f431;专栏&#xff1a;《网络》 &#x1f525;格言&#xff1a;你只管努力&#xff0c;剩下的交给时间&#xff01; 上篇文章对TCP可靠性机制讲解了一部分&#xff0c;这篇文章接着继续讲解。 &#x1f3a8;滑动窗口 在…

科技云报道:算力之战,英伟达再度释放AI“炸弹”

科技云报道原创。 近日&#xff0c;在计算机图形学顶会SIGGRAPH 2023现场&#xff0c;英伟达再度释放深夜“炸弹”&#xff0c;大模型专用芯片迎来升级版本。 英伟达在会上发布了新一代GH200 Grace Hopper平台&#xff0c;该平台依托于搭载全球首款搭载HBM3e处理器的新型Grac…

配置 yum/dnf 置您的系统以使用默认存储库

题目 给系统配置默认存储库&#xff0c;要求如下&#xff1a; YUM 的 两 个 存 储 库 的 地 址 分 别 是 &#xff1a; ftp://host.domain8.rhce.cc/dvd/BaseOS ftp://host.domain8.rhce.cc/dvd/AppStream vim /etc/yum.repos.d/redhat.repo [base] namebase baseurlftp:/…