• nginx隐藏版本号及nginx


    # 查看nginx安装了哪些插件

    nginx -V

    # 停止并卸载老的nginx

    1. systemctl stop nginx
    2. ps -ef|grep nginx

    # 备份老的配置

    1. find / -name "nginx"
    2. mv /etc/logrotate.d/nginx{,-bak}
    3. mv /etc/nginx{,-bak}
    4. mv /var/log/nginx
    5. mv /var/cache/yum/x86_64/7/nginx{,-bak}
    6. mv /var/cache/nginx{,-bak}
    7. mv /usr/sbin/nginx{,-bak}
    8. mv /usr/lib/debug/usr/lib64/nginx{,-bak}
    9. mv /usr/lib/debug/usr/lib64/perl5/vendor_perl/auto/nginx{,-bak}
    10. mv /usr/lib64/perl5/vendor_perl/auto/nginx{,-bak}
    11. mv /usr/lib64/nginx{,-bak}
    12. mv /usr/share/nginx{,-bak}
    13. mv /usr/libexec/initscripts/legacy-actions/nginx{,-bak}
    14. # mv /usr/lib/systemd/system/nginx-debug.service
    15. # mv /usr/lib/systemd/system/nginx.service
    16. mv /usr/share/doc/nginx-1.22.0{,-bak}
    17. mv /usr/share/man/man8/nginx.8.gz{,-bak}

    # 下载nginx源码,并解压,进入解压目录
     

    1. wget http://nginx.org/download/nginx-1.22.0.tar.gz
    2. tar -zxvf nginx-1.22.0.tar.gz
    3. cd nginx-1.22.0

    修改源码配置

    1. vi +13 src/core/nginx.h
    2. #define NGINX_VERSION "8.8.8"
    3. #define NGINX_VER " /" NGINX_VERSION
    4. vi +49 src/http/ngx_http_header_filter_module.c
    5. static u_char ngx_http_server_string[] = "Server: " CRLF;
    6. vi +36 src/http/ngx_http_special_response.c
    7. "
      "
      CRLF

    # 编译新的nginx

    1. ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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 --user=nginx --group=nginx --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='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
    2. make && make install

    编译中报错修复:

    yum -y install pcre-devel

    # 配置新的nginx配置

    1. mkdir -p /etc/nginx/conf.d/
    2. cp /etc/nginx-bak/nginx.conf /etc/nginx/
    3. cp /etc/nginx-bak/conf.d/default.conf /etc/nginx/conf.d/
    4. cp -a /etc/nginx-bak/ssl /etc/nginx/
    5. vi /etc/nginx/nginx.conf
    6. # 配置文件新增隐藏版本号
    7. http {
    8. server_tokens off;
    9. }

    启动测试

    1. systemctl start nginx
    2. cat /usr/lib/systemd/system/nginx.service
    3. [Unit]
    4. Description=nginx - high performance web server
    5. Documentation=http://nginx.org/en/docs/
    6. After=network-online.target remote-fs.target nss-lookup.target
    7. Wants=network-online.target
    8. [Service]
    9. Type=forking
    10. ExecStartPre=/bin/mkdir -p /var/run/nginx/
    11. PIDFile=/var/run/nginx.pid
    12. ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    13. ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
    14. ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
    15. [Install]
    16. WantedBy=multi-user.target
    17. systemctl daemon-reload
    18. systemctl restart nginx
    19. systemctl enable nginx


     

  • 相关阅读:
    SpringBoot简单使用MongoDB
    Towards Interpretable Video Anomaly Detection 论文阅读
    重入漏洞Victim
    最受欢迎的编程语言排行榜
    git+码云提交PR流程记录
    【C语言航路】第七站:结构体初阶
    kotlin实现HashMap
    java类和对象——static成员与代码块
    [PYTHON-CSP-前缀和]20210402-邻域均值
    分布式篇---第五篇
  • 原文地址:https://blog.csdn.net/liangkaiping0525/article/details/126845329