問題
我有一個 Web 應用程式,我想用 docker 容器化并通過 nginx 進行反向代理。此 Web 應用程式應接收音頻檔案(~200-500Mb)的上傳,因此我希望在上傳時將上傳進度事件發送到客戶端。
我決定將我的 docker 鏡像(參見下面的 dockerfile)建立在一個包含 glibc 的高山基礎上。從那里的想法是從 alpine 存盤庫安裝 nginx,并使用nginx 上傳進度模塊發送進度事件。該模塊默認編譯為 alpine 上的 nginx 模塊(參見 Alpine Repository)!
因此,我創建了一個簡單的nginx.conf檔案(見下文),它只在 http-block 中啟用upload_progress uploads 1m;指令并確保它被復制到容器中以/etc/nginx/nginx.conf.
然后我啟動容器,通過安裝 nginxapk并運行nginx -t. 但是,conf 檔案無法通過測驗并顯示以下錯誤訊息:
/ # nginx -t
nginx: [emerg] unknown directive "upload_progress" in /etc/nginx/nginx.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed
到目前為止的故障排除
該錯誤表明二進制檔案沒有編譯上傳進度模塊。但是,這與 alpine 存盤庫中記錄的內容相反。
我還驗證了該模塊是否存在于二進制檔案中,方法是運行一個 docker 容器-i并在其中執行nginx -V以獲取編譯它所用的所有模塊和標志的轉儲。它包含--add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-upload-progress-module-0.9.2/預期的必要內容(請參閱下面的 nginx -V 轉儲)。
nginx.conf 不是問題。當我在本地運行給定的 nginx conf 檔案時,我已將上傳進度模塊編譯到 nginx 中,它運行良好。
所以現在我很困惑,我做錯了什么?upload_progress當模塊存在于 nginx 二進制檔案中時,為什么我不能使用該指令?
dockerfile
FROM frolvlad/alpine-glibc
# Install dependencies
RUN apk update
RUN apk add --no-cache openrc nginx sqlite-libs
COPY ./nginx.conf /etc/nginx/nginx.conf
nginx.conf
# nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upload_progress uploads 1m;
types_hash_max_size 4096;
client_max_body_size 1000M;
sendfile on;
keepalive_timeout 600;
server {
server_name aldrune.com;
autoindex off;
listen 80;
root /frontend;
location /session_audio/ {
#CORS
add_header Access-Control-Allow-Origin '*';
alias /audiomedia/;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
nginx -V 轉儲
/ # nginx -V
nginx version: nginx/1.22.0
built with OpenSSL 1.1.1o 3 May 2022
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-threads --with-file-aio --without-pcre2 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --add-dynamic-module=/home/buildozer/aports/main/nginx/src/njs-0.7.4/nginx --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_devel_kit-0.3.1/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/traffic-accounting-nginx-module-2.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/array-var-nginx-module-0.05/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_brotli-1.0.0rc/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_cache_purge-2.5.1/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx_cookie_flag_module-1.1.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-dav-ext-module-3.0.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/echo-nginx-module-0.62/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/encrypted-session-nginx-module-0.09/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx-fancyindex-0.5.2/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_http_geoip2_module-3.3/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/headers-more-nginx-module-0.33/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-log-zmq-1.0.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/lua-nginx-module-0.10.21/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/lua-upstream-nginx-module-0.07/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/naxsi-1.3/naxsi_src --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nchan-1.2.8/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/redis2-nginx-module-0.15/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/set-misc-nginx-module-0.33/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-http-shibboleth-2.0.1/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_http_untar_module-1.1/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-upload-progress-module-0.9.2/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-upstream-fair-0.1.3/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/ngx_upstream_jdomain-1.3.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-vod-module-1.29/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-module-vts-0.1.18/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/mod_zip-1.2.0/ --add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-rtmp-module-1.2.2/
uj5u.com熱心網友回復:
該錯誤表明二進制檔案沒有編譯上傳進度模塊。
是的,不是。您將其編譯為動態模塊,使用
--add-dynamic-module=/home/buildozer/aports/main/nginx/src/nginx-upload-progress-module-0.9.2/
配置腳本引數,因此您需要使用load_module指令動態加載它:
load_module /path/to/nginx-upload-progress-module.so;
在您能夠使用它之前在頂級配置級別(或將其編譯為 nginx 二進制檔案作為靜態模塊)。
uj5u.com熱心網友回復:
@Ivan Shatsky 提供了公認的解決方案,我只是想更明確地說明我為將來閱讀的其他人做了什么。
在 alpine 上,您可以很容易地安裝 nginx 模塊,因為它們是在存盤庫中提供的。例如,對我來說有問題的模塊是here。
因此,您可以簡單地運行apk add nginx-mod-http-upload-progress,您將獲得所需的 so 檔案。apk安裝那些在/usr/lib/nginx/modules/ngx_http_uploadprogress_module.so.
知道了這一點,您可以load_module按照 Ivan 的建議添加命令:
load_module /usr/lib/nginx/modules/ngx_http_uploadprogress_module.so;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/492386.html
