Hello, I'm trying to configure NGINX with this dynamic module inside a Docker container, and in this post I found a way (maybe, but I'm not sure) to implement mod_zip using a reverse_proxy inside the nginx.conf file.
But I'm having an issue when trying to access the file server through the port 80, it returns the following error message:
[error] 30#30: *1 mod_zip: invalid file list from upstream while sending to client, client: 172.28.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "127.0.0.1"
Can someone help me with this issue? And maybe provide me an example that could work using NGINX inside a Docker container
I'm going to share my configuration files, in order to give a better understanding of this process:
There you have the Dockerfile file, which use two stages for the build, one for compile the hello_world_nginx module (only for testing purposes) and other for compile the mod_zip module.
And also add some files inside the files directory into a previously created directory, which is called /var/www which is need to serve the files into NGINX, as a file server, and the files could be in any uncompressed format, an then be selected and downloaded into a zip format using the mod_zip module.
Dockerfile:
FROM nginx:1.25.2 AS build
RUN apt-get update
RUN apt-get install -y build-essential \
wget \
git \
libpcre3 libpcre3-dev \
zlib1g zlib1g-dev \
openssl libssl-dev \
procps
RUN mkdir src
WORKDIR /src/
RUN wget http://nginx.org/download/nginx-1.25.2.tar.gz
RUN tar -xzvf nginx-1.25.2.tar.gz
RUN git clone https://github.com/perusio/nginx-hello-world-module.git
RUN git clone https://github.com/evanmiller/mod_zip.git
RUN git clone --branch=patch-1 https://github.com/dvershinin/nginx-unzip-module.git
# * Hello world module.
RUN cd nginx-1.25.2/ && ./configure --with-compat --add-dynamic-module=../nginx-hello-world-module
RUN cd nginx-1.25.2 && make modules
RUN cd nginx-1.25.2 && cp objs/ngx_http_hello_world_module.so /etc/nginx/modules
# * Zip module.
RUN cd nginx-1.25.2/ && ./configure --with-compat --add-dynamic-module=../mod_zip
RUN cd nginx-1.25.2 && make modules
RUN cd nginx-1.25.2 && cp objs/ngx_http_zip_module.so /etc/nginx/modules
#* Development stage.
FROM nginx:1.25.2 AS development-stage
COPY --from=build /etc/nginx/modules/ngx_http_hello_world_module.so /etc/nginx/modules
COPY --from=build /etc/nginx/modules/ngx_http_zip_module.so /etc/nginx/modules
RUN mkdir -p /var/www/
COPY ./files /var/www
RUN chown -R www-data:www-data /var/www/
COPY nginx.conf /etc/nginx
Then, inside the configuration of the nginx.conf file I have a statement to load the hello_world_module, only for testing purposes, and the mod_zip module.
When I use this nginx.conf file, it doesn't returns any error regarding the load of these modules, which seems to be right.
Then, inside the http block, I enable the gzip module, and define a server directive which is going to listen on 8080 port, and a location directive which is going to map the / path with the content inside the /var/www directory, which holds the uncompressed files that I need to display inside the file server, and then I need to be downloaded compressed with the .zip extension using the mod_zip module.
Finally, I define another server directive which is going to listen on 80 port and mapped the response of the first server directive. But, as I said, this not seems to be working.
nginx.conf:
load_module /etc/nginx/modules/ngx_http_hello_world_module.so;
load_module /etc/nginx/modules/ngx_http_zip_module.so;
worker_processes auto;
events {
worker_connections 1024;
}
http {
gzip on;
gzip_types text/plain text/css
application/json
application/javascript
text/xml
application/xml
application/xml+rss
text/javascript;
server {
listen 8080;
server_name 127.0.0.1;
location / {
# hello_world;
root /var/www;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
add_header X-Archive-Files 'zip';
# this line sets the name of the zip that the user gets
add_header Content-Disposition 'attachment; filename=example.zip';
add_header Content-Type application/zip;
}
}
server {
listen 80 default_server;
location / {
root /var/www;
proxy_hide_header X-Archive-Files;
proxy_set_header Accept-Encoding "";
proxy_pass_request_headers off;
proxy_pass http://127.0.0.1:8080;
}
}
}
Hello, I'm trying to configure NGINX with this dynamic module inside a Docker container, and in this post I found a way (maybe, but I'm not sure) to implement mod_zip using a reverse_proxy inside the
nginx.conf
file.But I'm having an issue when trying to access the file server through the port 80, it returns the following error message:
Can someone help me with this issue? And maybe provide me an example that could work using NGINX inside a Docker container
I'm going to share my configuration files, in order to give a better understanding of this process:
There you have the
Dockerfile
file, which use two stages for the build, one for compile thehello_world_nginx
module (only for testing purposes) and other for compile themod_zip
module.And also add some files inside the
files
directory into a previously created directory, which is called/var/www
which is need to serve the files into NGINX, as a file server, and the files could be in any uncompressed format, an then be selected and downloaded into azip
format using the mod_zip module.Dockerfile
:Then, inside the configuration of the
nginx.conf
file I have a statement to load thehello_world_module
, only for testing purposes, and themod_zip
module.When I use this
nginx.conf
file, it doesn't returns any error regarding the load of these modules, which seems to be right.Then, inside the
http
block, I enable thegzip
module, and define aserver
directive which is going to listen on8080
port, and a location directive which is going to map the/
path with the content inside the/var/www
directory, which holds the uncompressed files that I need to display inside the file server, and then I need to be downloadedcompressed
with the.zip
extension using themod_zip
module.Finally, I define another
server
directive which is going to listen on80
port and mapped the response of the firstserver
directive. But, as I said, this not seems to be working.nginx.conf
: