NGINX安全优化

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值