使用docker增加nginx
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,使用docker增加nginx autoindex美化功能话不多说先上效果图,先确定是不是你想要达到的结果##安装编译docker 环境我们这里采用的是nginx1.16.0 版本来进行编译安装的,如
千家信息网最后更新 2025年12月02日使用docker增加nginx
使用docker增加nginx autoindex美化功能
话不多说先上效果图,先确定是不是你想要达到的结果
##安装编译docker 环境
我们这里采用的是nginx1.16.0 版本来进行编译安装的,如果有需要你可以自行更改成别的nginx版本,Dockerfile如下
FROM alpine:latest AS alpine-baseWORKDIR /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 我们为了使镜像最小化这个都放在另外一个镜像里面来实现 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:latestMAINTAINER zhangshoufu zsf18163201@163.comWORKDIR /root#从上面一个镜像中把我们刚才下载安装的包拷贝到这个里面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 && \#安装编译安装需要的依赖 apk add --no-cache gcc libc-dev make openssl-dev pcre-dev zlib-dev linux-headers curl && \ cd /usr/local/nginx-1.16.0/ && \#执行编译安装 ./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 \#指定安装扩展模块的位置 --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 --from=alpine-base /usr/local/./Nginx-Fancyindex-Theme /etc/nginx/htmlEXPOSE 80CMD ["/bin/sh","-c","nginx -g 'daemon off;'"]我们执行构建动作
docker build -t apline-nginx:v2.0 -f Dockerfile .截止目前为止我们的docker 包已经构建完成了,
如何使用docker包
因为我们打包的docker包里面索引主题放在了/etc/nginx/html下面,所以我们就把网站根目录设在这个目录下,然后我们通过挂载的方式把网站目录挂载到这个目录下,我们先编写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; }}}
因为这个里面有两套主题,一套黑的一套白的,我们上面nginx配置文件使用的是白色的主题,如果我们想使用黑色的只需要把配置文件里面的`Nginx-Fancyindex-Theme-light`更换成`Nginx-Fancyindex-Theme-dark`即可。然后我们现在开始启动这个docker 容器```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 启动完成之后我们就可以在浏览器里面打开看到我们想要的界面了
主题
编译
文件
目录
网站
镜像
拷贝
根目录
模块
版本
配置
最小
位置
功能
动作
容器
效果
效果图
方式
浏览器
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
标准普尔数据库
sql检查数据库修复工具
小米wifi出现连接不上服务器
怎样确定服务器的远程端口
坚持网络安全同步发展三同步
在网络安全保护的方式中
开福区软件开发工程师培训
多线程更新数据库失败撤销
金蝶软件找不到服务器
太原软件开发专业学校排名
软件开发的最终目标
sql数据库中的查找命令
300字网络安全靠大家演讲稿
鼎牛网络技术有限公司
国内最大服务器制造
你愿意做金融软件开发嘛
c 微信窗口发送数据库
web版oracle数据库管理
中文期刊数据库的用途
群晖服务器网络速度
网络技术安全对抗赛
ibm服务器销售渠道
深圳系统软件开发公司排名
万方中国标准数据库
关于管线数据库更新技术方面
博山进销存erp软件开发
超威服务器BIOS设置带外
网络安全第四十七条处罚
设备数据库如何建立
局域网内电脑都无法访问服务器