1.测试机器Dockerfile 编译安装nginx.1.20.2镜像
FROM centos:centos7.6.1810
RUN yum install epel-release -y && yum -y install vim net-tools bridge-utils firewalld bc iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel systemd-devel bash-completion traceroute psmisc top net-tools htop
ADD nginx-1.20.2.tar.gz /usr/
WORKDIR /usr/nginx-1.20.2
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
RUN ./configure --prefix=/application/nginx --user=www --group=www --with-http_ssl_module --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
RUN make
RUN make install
CMD /usr/sbin/groupadd -f www
CMD /usr/sbin/useradd -g www www
#ENV PATH $PATH:/usr/local/nginx/sbin
RUN ln -s /application/nginx/sbin/nginx /usr/sbin/nginx
CMD /bin/bash -c "nginx -g daemon off;"
构建完成生成nginx:v1.20.2镜像
2.优化nginx软件名
需要修改三个文件
cat /usr/nginx-1.20.2/src/http/ngx_http_header_filter_module.c
cat /usr/nginx-1.20.2/src/http/ngx_http_header_filter_module.c |grep Server
cat /usr/nginx-1.20.2/src/http/ngx_http_special_response.c|grep center -n
修改完成后重新编译Nginx
RUN ./configure --prefix=/application/nginx --user=www --group=www --with-http_ssl_module --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
启动Nginx 并验证
导出镜像
docker commit -a "zk" -m "nginx" 53dfa3d847ac nginx:test
docker save nginx.tar.gz 60c6f1d47605