一、nginx安装第三方模块[apt安装、源码安装]

ubuntu

nginx一般都需要重新编译

一、安装

无区别:apt安装与源码安装没有太多区别,区别最多的就是路径,还有源码安装可能已经提前下载有源码,而apt没有需要下载

解释:nginx本体是通过apt install nginx安装,但是需要增加第三方模块,这时候需要去官网按照源码按照对应版本下载(nginx -v查看)(因为nginx增减模块一般都需要重新编译,而apt安装的是已经编译好的,所以此时应该找其源码,增减配置参数,重新编译)

原理:由nginx -V里面的configure配置参数可知道--sbin-path路径(没有出现默认安装在/usr/share/nginx/sbin/nginx)其就是nginx核心二进制文件可执行文件,其是第一次编译安装nginx时出现的,我们并非需要替换它,因为例如nginx -s stop或者systemctl start nginx背后起作用的是/usr/sbin/nginx所以我们需要将其替换为新编译的(在/nginx-18.0/objs/下的nginx文件(make编译后出现))

示例:

  • 目地:让nginx能正向代理https请求;需要第三方库的地址https://github.com/chobits/ngx_http_proxy_connect_module

  • 下载并解压第三方模块:

    • wget https://gitcode.net/mirrors/chobits/ngx_http_proxy_connect_module/-/archive/master/ngx_http_proxy_connect_module-master.tar.gz
    • tar -zxvf ngx_http_proxy_connect_module-master.tar.gz
  • 打补丁(这个需要根据自己的版本选择不同的补丁,自行去上面的地址查看)(此时需要提前cd到nginx-1.18.0目录下)(路径根据自己的来): patch -p1 < /opt/nginx/nginxPatch/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1018.patch

  • configure(路径根据自己的来):这个操作为./configure + 你原来在nginx -V(configure参数看到的内容) + --add-module=/opt/user/ngx_http_proxy_connect_module-master

    • 例子(apt安装版本的):
      configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-KTLRnK/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-module=/opt/nginxPatch/ngx_http_proxy_connect_module-master
  • 编译:make此时nginx核心二进制可执行文件就编译在了objs/nginx(下一步无需make install其是为了根据configure配置创建目录(我们只是需要新编译的nginx))

  • 复制(呼应上面的原理 )(最好先备份失误还可以回滚:cp /usr/sbin/nginx /usr/sbin/nginx.back):cp objs/nginx /usr/sbin/nginx

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 macOS 上安装 nginx第三方模块可以使用 Homebrew 包管理器来简化过程。以下是安装第三方模块的步骤: 1. 首先,确保您已经安装了 Homebrew。如果您还没有安装,可以在终端中运行以下命令来安装 Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装 nginx。在终端中运行以下命令来使用 Homebrew 安装 nginx: ``` brew install nginx ``` 3. 找到您想要安装第三方 nginx 模块。您可以通过在搜索引擎上搜索或访问模块的官方网站来找到合适的模块。 4. 下载并解压第三方模块的源代码。将源代码解压到一个您可以方便访问的位置。 5. 进入解压后的模块源代码目录,并使用 `./configure` 命令配置编译选项。在这个命令中,您可以通过添加 `--add-dynamic-module=/path/to/module` 来指定要安装模块。例如: ``` ./configure --add-dynamic-module=/path/to/module ``` 请将 `/path/to/module` 替换为您要安装模块的实际路径。 6. 完成配置后,运行 `make` 命令编译 nginx。 7. 编译完成后,在终端中运行以下命令将编译好的模块复制到 nginx模块目录: ``` cp objs/*.so /usr/local/Cellar/nginx/{version}/libexec/modules/ ``` 请将 `{version}` 替换为您当前安装nginx 版本号。 8. 在终端中运行以下命令启动 nginx: ``` brew services start nginx ``` 现在,您已经成功安装第三方模块,并且可以在 nginx 的配置文件中启用和配置它们。 请注意,安装第三方模块可能需要一些编译工具和依赖项。如果出现任何错误或依赖项缺失,您可能需要安装相应的工具和库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值