使用docker增加nginx

使用docker增加nginx autoindex美化功能

話不多說先上效果圖,先確定是不是你想要達(dá)到的結(jié)果
使用docker增加nginx

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、谷城網(wǎng)站維護(hù)、網(wǎng)站推廣。

##安裝編譯docker 環(huán)境
我們這里采用的是nginx1.16.0 版本來進(jìn)行編譯安裝的,如果有需要你可以自行更改成別的nginx版本,Dockerfile如下

FROM alpine:latest AS alpine-base
WORKDIR /usr/local
#更換apline的源為阿里云的
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 && \
#安裝wget 和git 我們?yōu)榱耸圭R像最小化這個(gè)都放在另外一個(gè)鏡像里面來實(shí)現(xiàn)
    apk add --no-cache wget git && \
#下載nginx包
    wget http://nginx.org/download/nginx-1.16.0.tar.gz && \
    tar xvf nginx-1.16.0.tar.gz && \
#克隆我們需要的模塊和主題
    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
#從上面一個(gè)鏡像中把我們剛才下載安裝的包拷貝到這個(gè)里面
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 && \
#安裝編譯安裝需要的依賴
    apk add --no-cache gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers curl && \
    cd /usr/local/nginx-1.16.0/ && \
#執(zhí)行編譯安裝
    ./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 \
#指定安裝擴(kuò)展模塊的位置
     --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
#把主題拷貝到網(wǎng)站根目錄下
COPY --from=alpine-base /usr/local/./Nginx-Fancyindex-Theme /etc/nginx/html
EXPOSE 80
CMD ["/bin/sh","-c","nginx -g 'daemon off;'"]

我們執(zhí)行構(gòu)建動(dòng)作

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

截止目前為止我們的docker 包已經(jīng)構(gòu)建完成了,

如何使用docker包

因?yàn)槲覀兇虬膁ocker包里面索引主題放在了/etc/nginx/html下面,所以我們就把網(wǎng)站根目錄設(shè)在這個(gè)目錄下,然后我們通過掛載的方式把網(wǎng)站目錄掛載到這個(gè)目錄下,我們先編寫nginx.conf文件

```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;
    }
}

}

因?yàn)檫@個(gè)里面有兩套主題,一套黑的一套白的,我們上面nginx配置文件使用的是白色的主題,如果我們想使用黑色的只需要把配置文件里面的`Nginx-Fancyindex-Theme-light`更換成`Nginx-Fancyindex-Theme-dark`即可。
然后我們現(xiàn)在開始啟動(dòng)這個(gè)docker 容器

```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 

啟動(dòng)完成之后我們就可以在瀏覽器里面打開看到我們想要的界面了
使用docker增加nginx

分享名稱:使用docker增加nginx
當(dāng)前網(wǎng)址:http://bm7419.com/article4/pccdoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊微信小程序、關(guān)鍵詞優(yōu)化、網(wǎng)頁設(shè)計(jì)公司、全網(wǎng)營銷推廣、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司