Nginx 下载编译安装

前言

通过第三方安装的 nginx 往往日志/配置文件都不在一起。如果有多台服务器,每台服务器都得重新安装,非常麻烦,所以一般推荐使用二进制压缩文件自己编译安装。而且也可以定制自己所需功能。

依赖下载

nginx 在编译时会依赖一些第三方库,我们通常将这些第三方库直接打包到nginx里。这样迁移时就不会依赖环境里是否安装里这些第三方库了

下载 pcre

https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
或者
https://ftp.pcre.org/pub/pcre/

下载 openssl

https://www.openssl.org/source/

下载 nginx-rtmp-module

流媒体使用

https://github.com/arut/nginx-rtmp-module/releases

下载 gzip

http://www.zlib.net/fossils/

下载 nginx

http://nginx.org/en/download.html

上述压缩包下载后全部解压

解压命令: tar -zxvf 文件名称

解压后效果

编译

进入到 cd nginx-1.18.0 目录 运行下面脚本 这里我们将输出目录设定为 `/srv/nginx

第一步

./configure --prefix=/srv/nginx 
--add-module=../nginx-rtmp-module-1.2.1 
--with-openssl=../openssl-1.1.1i 
--with-openssl-opt=no-shared 
--with-http_ssl_module 
--with-pcre=../pcre-8.40 
--with-http_flv_module 
--with-http_mp4_module  
--with-stream 
--with-http_stub_status_module 
--with-http_realip_module 
--with-http_gzip_static_module 
--with-zlib=../zlib-1.2.11

第二步

make && make install

编译完成后, 在 /srv/nginx 这个目录下有全部的nginx文件。 将整个文件打包,可以放到任意一台linux机器上运行。

编译参数参考: 这里 https://blog.51cto.com/u_14184380/2456515

简单描述

  1. nginx编译出来是一个可执行二进制程序。

  2. win有官网编译好的二进制程序,其他平台没有

  3. 编译大概流程

    1. 安装编译工具 gcc-c++ yum install -y gcc-c++
    2. 下载依赖包
    3. 下载源码包
    4. configure构建, 最复杂的就是需要哪些编译参数,上面的编译参数就可以满足大多数情况了。
    5. make && make install
  4. 上面就构建完成了。

博客中所涉及到的图片都有版权,请谨慎使用
原文地址:https://www.cnblogs.com/shuiche/p/14377328.html