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.pswp.cn/news/37541.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/37541.shtml
英文地址,請注明出處:http://en.pswp.cn/news/37541.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

遞歸的用法和例子

b站視頻:https://www.bilibili.com/video/BV1iS4y1e7MJ/?spm_id_from333.999.0.0&vd_source1717654b9cbbc6a773c2092070686a95 # 遞歸的定義:其實就是自己調用自己,一般用函數的形式來進行 """ 特點: 1、一定…

item_review-獲得TB商品評論

一、接口參數說明: item_review-獲得TB商品評論,點擊更多API調試,請移步注冊API賬號點擊獲取測試key和secret 公共參數 請求地址: https://api-gw.onebound.cn/taobao/item_review 名稱類型必須描述keyString是調用key(點擊獲取…

輕拍牛頭(約數)

題意&#xff1a;求ai在n個數中&#xff0c;ai可以整除的數有多少個&#xff0c;不包括ai自己。 分析&#xff1a;暴力寫需要n^2的時間復雜度&#xff0c;此時想一下預處理每個數的倍數&#xff0c;約數和倍數是有關系的&#xff0c;把每個數的倍數都加上1. #include<bits…

騰訊云SA3服務器AMD處理器CPU網絡帶寬性能詳解

騰訊云AMD服務器SA3實例CPU采用2.55GHz主頻的AMD EPYCTM Milan處理器&#xff0c;睿頻3.5GHz&#xff0c;搭載最新一代八通道DDR4&#xff0c;內存計算性能穩定&#xff0c;默認網絡優化&#xff0c;最高內網收發能力達1900萬pps&#xff0c;最高內網帶寬可支持100Gbps。騰訊云…

typeScript 之 運算符

工具&#xff1a; PlayGround 算術運算符 運算符描述加-減*乘/除%取模(求余)自增–自減 注意和--&#xff0c;實例&#xff1a; let value 0; console.log(value); //0, 先顯示再增加后為1 console.log(value); //2&#xff0c;先增加后為2再顯示關系運算符 運算符描述 …

list.stream.filter,List<List>轉換為List

1.filter過濾 返回符合查詢條件的集合//過濾所有deviceType為1的List<DeviceWorkTimeEntity> list entities.stream().filter(a -> "1".equals(a.getDeviceType())).toList(); 2.List<List>轉換為List 可以使用流(Stream)的flatMap操作 public cl…

嵌入式Linux驅動開發系列五:Linux系統和HelloWorld

三個問題 了解Hello World程序的執行過程有什么用? 編譯和執行&#xff1a;Hello World程序的執行分為兩個主要步驟&#xff1a;編譯和執行。編譯器將源代碼轉換為可執行文件&#xff0c;然后計算機執行該文件并輸出相應的結果。了解這個過程可以幫助我們理解如何將代碼轉化…

從一到無窮大 #10 討論 Apache IoTDB 大綜述中看到的優劣勢

本作品采用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。 本作品 (李兆龍 博文, 由 李兆龍 創作)&#xff0c;由 李兆龍 確認&#xff0c;轉載請注明版權。 文章目錄 引言問題定義新技術數據模型schemalessTsfile設計雙MemTable高級可擴展查詢其他 IotD…

兩天入門Linux、搭建Spring環境 第一天

一、Linux簡介 1.什么是Linux 一個操作系統&#xff0c;未來公司里面會用到、接觸的新操作系統。 2.為什么學Linux (1)個人職務需要&#xff0c;肯定會接觸到Linux (2)職業發展&#xff0c;以后的發展肯定需要掌握Linux的許多使用方法 3.學哪些內容 (1)Linux基本介紹 (2)…

EnableAutoConfiguration Attributes should be specified via @SpringBootApplic

在排除數據源加載時&#xff0c;發現這個注解EnableAutoConfiguration(exclude{DataSourceAutoConfiguration.class})會飄紅 這是因為在SpringBootApplication中已經有EnableAutoConfiguration注解了&#xff1b; 所以把它改寫成以下的格式即可

圖像變形之移動最小二乘算法(MLS)

基本原理 基于移動最小二乘的圖像變形是通過一組源控制點和目標控制點來控制變形&#xff0c;對于每一個待求變形后位置的點而言&#xff0c;根據預設的形變類型&#xff08;如仿射變換、相似變換、剛性變換&#xff09;求解一個最小二乘優化目標函數估計一個局部的坐標變換矩陣…

metaRTC7 demo mac/ios編譯指南

概要 metaRTC7.0開始全面支持mac/ios操作系統&#xff0c;新版本7.0.023 mac os demo 包含有srs/zlm的推拉流演示。發布版自帶了x64版第三方類庫&#xff0c;arm版第三方類庫還需開發者自己編譯。 源碼下載 下載文件metartc7.023.7z https://github.com/metartc/metaRTC/re…

?亞商投資顧問 早餐FM/0815生成式人工智能服務管理

01/亞商投資顧問 早間導讀 商務部等9部門&#xff1a;促進農村大宗商品消費更新換代中央財辦等九部門印發指導意見推動農村流通高質量發展《生成式人工智能服務管理暫行辦法》今起施行 02/亞商投資顧問 新聞早餐 // 熱點聚焦 // 商務部等9部門印發《縣域商業三年行動計劃&…

基于Java+SpringBoot+Vue的網吧管理系統設計與實現(源碼+LW+部署文檔等)

博主介紹&#xff1a; 大家好&#xff0c;我是一名在Java圈混跡十余年的程序員&#xff0c;精通Java編程語言&#xff0c;同時也熟練掌握微信小程序、Python和Android等技術&#xff0c;能夠為大家提供全方位的技術支持和交流。 我擅長在JavaWeb、SSH、SSM、SpringBoot等框架…

智頭條|DFM-2大模型吹熱智能家居,360安全云正式發布

行業動態 DFM-2大模型吹熱智能家居 近期,思必馳行業語言計算大模型DFM-2正式發布,也帶來了人機交互能力的提升和優秀的技術落地能力。DFM-2大模型與DUI平臺結合推出DUI2.0,完成了對話式AI全鏈路技術的升級,推進深度產業應用。在智能家居領域,目前思必馳已與海信、長虹美菱、老…

Vue3封裝一個左側可拖拽折疊的側邊欄布局

功能 1、點擊左側側邊欄可折疊或打開 2、左側側邊欄可拖拽 代碼 <template><div class"fold-left-box"><div class"fold-left-box-left" :style"{ width: asideWidth px }" v-show"asideWidth > 0">left<…

PAT 1097 Deduplication on a Linked List

個人學習記錄&#xff0c;代碼難免不盡人意 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value o…

實例038 設置窗體在屏幕中的位置

實例說明 在窗體中可以設置窗體居中顯示&#xff0c;本例通過設置窗體的Left屬性和Top屬性可以準確設置窗體的位置。運行本例&#xff0c;效果如圖1.38所示。 技術要點 設置窗體在屏幕中的位置&#xff0c;可以通過設置窗體的屬性來實現。窗體的Left屬性表示窗體距屏幕左側的…

angular 子組件ngOnChanges監聽@input傳入的輸入屬性

在進入主題之前&#xff0c;先了解一下angular的生命周期。 生命周期 鉤子分類 指令與組件共有的鉤子 ngOnChangesngOnInitngDoCheckngOnDestroy 組件特有的鉤子 ngAfterContentInitngAfterContentCheckedngAfterViewInitngAfterViewChecked 生命周期鉤子的作用及調用順序 …

Makefile多個子文件夾

首先&#xff0c;目錄結構&#xff1a; 其中根目錄Makefile主要作用是調用其他子文件夾Makefile&#xff0c;每個子模塊執行各自編譯后在build文件夾下生成obj文件&#xff0c;最后再執行build文件夾下Makefile進行鏈接。 根目錄Makefile&#xff1a; TARGET ACT_Drv ##SRC_D…