[英]How to install a module on nginx?
運行 nginx -t 時出現此錯誤:
nginx: [emerg] unknown directive "subs_filter_types" in /etc/nginx/sites-enabled/my.site.com.conf:285
nginx: configuration file /etc/nginx/nginx.conf test failed
所以我需要安裝替換過濾器模塊,並在 nginx 文檔https://www.nginx.com/resources/wiki/modules/substitutions/#subs-filter-types 中說要運行這些命令:
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
./configure --add-module=/path/to/module
問題是我的 nginx 安裝和 git 存儲庫中的任何地方都沒有配置腳本。 我真的不明白。 至少我想知道那個 nginx 配置腳本的內容。
您所指的說明用於編譯安裝。
假設您想將模塊添加到現有的NGINX 安裝中,下面是使事情運行的通用步驟。
/usr/local/src/nginx
git clone
NGINX 模塊的源代碼到你的系統,例如/usr/local/src/nginx-module-foo
cd /usr/local/src/nginx
。 您將在此處找到configure
腳本。 您將基本上使用特定模塊的config
位置來配置 NGINX,因此下一步:./configure --add-dynamic-module=../nginx-module-foo --with-compat
make
作為編譯的resulf你將有模塊.so
文件的地方objs
的您NGINX源目錄。 然后您將它復制到例如/usr/lib64/nginx/modules/
目錄。
為了讓你現有的 NGINX 加載模塊,添加load_module modules/foo.so;
在/etc/nginx/nginx.conf
的最頂部。
您可以解讀整個編譯方法的許多缺點:一個是在生產系統上安裝了編譯軟件 ( gcc
),另一個是在升級 NGINX 或模塊時必須重新執行所有這些步驟。
出於上述原因,您可能想要搜索第三方模塊的打包安裝。
對於 CentOS/RHEL 系統,您可能想查看 GetPageSpeed 存儲庫(訂閱軟件,我傾向於提及它,因為我是維護者。但在撰寫本文時,這對於 CentOS/RHEL 8 是免費的. 安裝你想要的模塊, 歸結為幾個命令:
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-substitutions
對於基於 Debian 的系統,可能存在替代的 PPA。
只需將前綴subs替換為sub 。
默認 nginx 1.10.3 安裝 (Ubuntu 16.04.5 LTS)
nginx -V應該有標志--with-http_sub_module來使用sub_ * 指令。
用法示例:
sub_filter_types text/html text/css text/xml;
sub_filter 'needle' 'replacement';
sub_filter_once off;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.