Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use docker to increase nginx

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Using docker to add nginx autoindex beautification

Not much to say first on the renderings, first determine whether you want to achieve the results

##Install and compile docker environment

We use nginx version 1.16.0 to compile and install. If necessary, you can change it to another nginx version. Dockerfile is as follows

FROM alpine:latest AS alpine-baseWORKDIR /usr/local#replace apline's source for Aliyun's 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 put them in another mirror to minimize mirroring 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 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:latestMAINTAINER zhangshoufu zsf18163201@163.comWORKDIR /root#Copy the package we just downloaded and installed from the above image to this COPY --from=alpine-base /usr/local/nginx-1.16.0 /usr/local/nginx-1.16.0RUN 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 dependencies required for compilation 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 compile install ./ 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 the extension module --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 website COPY --from=alpine-base /usr/local/./ Nginx-Fancyindex-Theme /etc/nginx/htmlEXPOSE 80CMD ["/bin/sh","-c","nginx -g 'daemon off;'"]

We perform build actions

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

So far our docker package has been built,

How to use docker packages

Because the index theme in our packaged docker package is placed under/etc/nginx/html, so we set the website root directory in this directory, and then we mount the website directory to this directory by mounting. We first 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 sets of themes in this, one set of black and one set of white, we use the white theme in the nginx configuration file above. If we want to use black, we just need to replace `Nginx-Fancyindex-Theme-light` in the configuration file with `Nginx-Fancyindex-Theme-dark`. Then we now start this docker container ```bashdocker 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 launching, we can open it in the browser and see the interface we want.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report