Nginx

無法啟動 Nginx,Brotli 配置錯誤

  • April 17, 2022

我有一個 nginx 伺服器設置作為 Debian 9 作業系統上的 apache2 的反向代理。Apache2 執行在與 80 不同的埠上。我試圖使用 certbot 更新站點的證書,並且在此過程中的某處執行了此命令:

$ sudo apt install python3-certbot-nginx

我認為這在我的機器上安裝了一個新的 nginx 伺服器副本(如果我錯了,請糾正我),從那時起 nginx 就無法啟動。以下是測試命令的結果:

nginx -t:

nginx: [emerg] dlopen() "/usr/share/nginx/nginx/modules/ngx_http_brotli_filter_module.so" failed (/usr/share/nginx/nginx/modules/ngx_http_brotli_filter_module.so: cann
ot open shared object file: No such file or directory) in /etc/nginx/modules.conf.d/brotli.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed

nginx -V:

nginx version: nginx/1.10.3
built with OpenSSL 1.1.0l  10 Sep 2019
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-8G38mz/nginx-1.10.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time 
-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --er
ror-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=/va
r/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-tem
p-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_r
equest_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --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-dynamic-module=/build/nginx-8G38mz/nginx-1.10.3/debian/modules/nginx-auth-pam --add-dynamic-m
odule=/build/nginx-8G38mz/nginx-1.10.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-8G38mz/nginx-1.10.3/debian/modules/nginx-echo --add-dynami
c-module=/build/nginx-8G38mz/nginx-1.10.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/nginx-8G38mz/nginx-1.10.3/debian/modules/ngx_http_substitution
s_filter_module

sudo systemctl status nginx:

nginx.service - A high performance web server and a reverse proxy server
  Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
  Active: failed (Result: exit-code) since Mon 2022-04-11 01:20:12 CEST; 14min ago
    Docs: man:nginnginx: [emerg] dlopen() "/usr/share/nginx/nginx/modules/ngx_http_brotli_filter_module.so" failed (/usr/share/nginx/nginx/modules/ngx_http_brotli_filter_module.so: cann
ot open shared object file: No such file or directory) in /etc/nginx/modules.conf.d/brotli.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failedx(8)
 Process: 22395 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Apr 11 01:20:12 cp-com-vm systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 11 01:20:12 cp-com-vm nginx[22395]: nginx: [emerg] dlopen() "/usr/share/nginx/nginx/modules/ngx_http_brotli_filter_module.so" failed (/usr/share/nginx/nginx/module
Apr 11 01:20:12 cp-com-vm nginx[22395]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 11 01:20:12 cp-com-vm systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 11 01:20:12 cp-com-vm systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 11 01:20:12 cp-com-vm systemd[1]: nginx.service: Unit entered failed state.
Apr 11 01:20:12 cp-com-vm systemd[1]: nginx.service: Failed with result 'exit-code'.

nginx.conf:

  #user  nginx;
worker_processes  1;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /var/run/nginx.pid;

include /etc/nginx/modules.conf.d/*.conf;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;
#tcp_nodelay        on;

#gzip  on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";

server_tokens off;

include /etc/nginx/conf.d/*.conf;
client_max_body_size 512M;
}

# override global parameters e.g. worker_rlimit_nofile
include /etc/nginx/*global_params;

brotli.conf:

load_module nginx/modules/ngx_http_brotli_filter_module.so;
load_module nginx/modules/ngx_http_brotli_static_module.so;

我已經嘗試了很多來自不同站點的關於如何讓我的伺服器恢復無濟於事的答案,有人可以指出確切的問題嗎?僅供參考-我之後能夠續訂證書,所以現在我只剩下這個問題了。TIA

無論我嘗試了什麼,我都無法修復我當時安裝的 nginx。即使我單獨安裝了 brotli 並嘗試在配置中對其進行註釋,我的 nginx.conf 總是失敗。

我不得不清除 nginx 實例並重新安裝它以使其重新啟動並執行:

apt-get purge nginx nginx-common nginx-full
apt-get install nginx

引用自:https://serverfault.com/questions/1098295