Nginx隱藏版本號
在生產環境中,需要隱藏Nginx的版本號,以避免安全漏洞的泄露
查看方法
使用fiddler工具在Windows客戶端查看Nginx版本號
在centos系統中使用“curl -I 網址” 命令查看
Nginx隱藏版本號的方法
修改配置文件法
修改源碼法
一,安裝Nginx
1,在Linux上使用遠程共享獲取文件并掛載到mnt目錄下
[root@localhost ~]# smbclient -L //192.168.100.3/ ##遠程共享訪問Enter SAMBA/root's password: Sharename Type Comment --------- ---- ------- LNMP-C7 Disk [root@localhost ~]# mount.cifs //192.168.100.3/LNMP-C7 /mnt ##掛載到/mnt目錄下
2,解壓源碼包到/opt下,并查看
[root@localhost ~]# cd /mnt ##切換到掛載點目錄[root@localhost mnt]# lsDiscuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gzmysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz[root@localhost mnt]# tar zxvf nginx-1.12.2.tar.gz -C /opt ##解壓Nginx源碼包到/opt下[root@localhost mnt]# cd /opt/ ##切換到解壓的目錄下[root@localhost opt]# lsnginx-1.12.2 rh
3,安裝編譯需要的環境組件包
[root@localhost opt]# yum -y install /gcc / //c語言gcc-c++ / //c++語言pcre-devel / //pcre語言工具zlib-devel //數據壓縮用的函式庫
4,創建程序用戶nginx并編譯Nginx
[root@localhost opt]# useradd -M -s /sbin/nologin nginx ##創建程序用戶,安全不可登陸狀態[root@localhost opt]# id nginxuid=1001(nginx) gid=1001(nginx) 組=1001(nginx)[root@localhost opt]# cd nginx-1.12.0/ ##切換到nginx目錄下[root@localhost nginx-1.12.0]# ./configure / ##配置nginx> --prefix=/usr/local/nginx / ##安裝路徑> --user=nginx / ##用戶名> --group=nginx / ##用戶組> --with-http_stub_status_module ##狀態統計模塊
5,編譯和安裝
[root@localhost nginx-1.12.0]# make ##編譯...[root@localhost nginx-1.12.0]# make install ##安裝...[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ##創建軟連接讓系統識別nginx啟動腳本
6,制作管理腳本,便于使用service管理使用
[root@localhost nginx]# cd /etc/init.d/ ##切換到啟動配置文件目錄[root@localhost init.d]# lsfunctions netconsole network README[root@localhost init.d]# vim nginx ##編輯啟動腳本文件#!/bin/bash# chkconfig: - 99 20 ##注釋信息# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx" ##設置變量為nginx命令文件PIDF="/usr/local/nginx/logs/nginx.pid" ##設置變量PID文件 進程號為5346case "$1" in start) $PROG ##開啟服務 ;; stop) kill -s QUIT $(cat $PIDF) ##關閉服務 ;; restart) ##重啟服務 $0 stop $0 start ;; reload) ##重載服務 kill -s HUP $(cat $PIDF) ;; *) ##錯誤輸入提示 echo "Usage: $0 {start|stop|restart|reload}" exit 1esacexit 0[root@localhost init.d]# chmod +x /etc/init.d/nginx ##給啟動腳本執行權限[root@localhost init.d]# chkconfig --add nginx ##添加到service管理器中[root@localhost init.d]# service nginx stop ##就可以使用service控制nginx[root@localhost init.d]# service nginx start
新聞熱點
疑難解答