Using docker to increase nginx

Use docker to add nginx autoindex beautification

Don't talk more, start with the effect map, and decide if you want to achieve it or not

##Install the compiler docker environment
Here we use nginx version 1.16.0 to compile and install. If you need to change to another version of nginx, Dockerfile is as follows

FROM alpine:latest AS alpine-base
WORKDIR /usr/local
#Replace apline from Ali Yun
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories && \
    echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories && \
    apk update && \
#Install wget and git We do this in another mirror to minimize the mirror
    apk add --no-cache wget git && \
#Download nginx package
    wget http://nginx.org/download/nginx-1.16.0.tar.gz && \
    tar xvf nginx-1.16.0.tar.gz && \
#Clone the modules and themes we need
    git clone https://github.com/Naereen/Nginx-Fancyindex-Theme.git && \
    git clone https://github.com/aperezdc/ngx-fancyindex.git && \
    mkdir /usr/local/nginx-1.16.0/model && \
    mv ./ngx-fancyindex /usr/local/nginx-1.16.0/model/

FROM alpine:latest
MAINTAINER zhangshoufu zsf18163201@163.com
WORKDIR /root
#Copy the package we just downloaded and installed into this one from the image above
COPY --from=alpine-base /usr/local/nginx-1.16.0 /usr/local/nginx-1.16.0
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories && \
    echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories && \
    apk update && \
#Install the dependencies required for compilation and installation
    apk add --no-cache gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers curl && \
    cd /usr/local/nginx-1.16.0/ && \
#Perform compilation installation
    ./configure --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --modules-path=/usr/lib/nginx/modules \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --http-client-body-temp-path=/var/cache/nginx/client_temp \
    --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
    --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
    --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
    --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
#Specify where to install extensions
     --add-module=/usr/local/nginx-1.16.0/model/ngx-fancyindex \
    --with-compat \
    --with-file-aio \
    --with-threads \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_mp4_module \
    --with-http_random_index_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-stream --with-stream_realip_module \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.16.0/debian/debuild-base/nginx-1.16.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
    --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' && \
    make && make install && \
    mkdir -p /var/cache/nginx/client_temp && \
    rm -rf /usr/local/nginx-1.16.0
#Copy the theme to the root directory of the site
COPY --from=alpine-base /usr/local/./Nginx-Fancyindex-Theme /etc/nginx/html
EXPOSE 80
CMD ["/bin/sh","-c","nginx -g 'daemon off;'"]

We perform build actions

 docker build  -t apline-nginx:v2.0 -f Dockerfile .

Our docker package has been built so far.

How to use the docker package

Because the index theme in our packaged docker package is placed under / etc/nginx/html, we set the site root directory under this directory, and then we mount the site directory into this directory by mounting it. First we write the nginx.conf file

```nginx.conf
worker_processes auto;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

fancyindex on;
fancyindex_exact_size off;
fancyindex_localtime on;
fancyindex_header "/Nginx-Fancyindex-Theme-light/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme-light/footer.html";
fancyindex_ignore "examplefile.html";
fancyindex_ignore "Nginx-Fancyindex-Theme-light";
fancyindex_name_length 255;

server {
    listen       80;
    server_name  localhost;

    location / {
        autoindex on;
        root   /etc/nginx/html;
        index  index.html index.htm;
    }
}

}

Because there are two themes inside, one black and one white, the nginx profile above uses a white theme. If we want to use black, we just need to replace `Nginx-Fancyindex-Theme-light'inside the profile with `Nginx-Fancyindex-Theme-dark'.
Then we'll start the docker container now

```bash
docker run -id --name voice_nginx -p 9999:80 -v /home/monitor/:/etc/nginx/html/monitor -v /home/monitor/nginx.conf:/etc/nginx/nginx.conf --restart=always apline-nginx:v2.0 

After the boot is complete, we can open the browser to see the interface we want

Tags: Operation & Maintenance Nginx Docker git github

Posted on Thu, 07 Nov 2019 16:05:48 -0500 by finkrattaz