成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何隱藏Nginx的版本號-創(chuàng)新互聯(lián)

如何隱藏Nginx的版本號?針對這個問題,今天小編總結(jié)這篇有關(guān)Nginx版本號的文章,希望能幫助更多想解決這個問題的朋友找到更加簡單易行的辦法。

主要從事網(wǎng)頁設(shè)計、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機版網(wǎng)站建設(shè))、自適應網(wǎng)站建設(shè)、程序開發(fā)、微網(wǎng)站、小程序開發(fā)等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站設(shè)計、做網(wǎng)站、網(wǎng)絡(luò)營銷經(jīng)驗,集策劃、開發(fā)、設(shè)計、營銷、管理等多方位專業(yè)化運作于一體,具備承接不同規(guī)模與類型的建設(shè)項目的能力。

查看方法

使用fiddler工具在Windows客戶端查看Nginx版本號
在centos系統(tǒng)中使用“curl -I 網(wǎng)址” 命令查看

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]# ls
Discuz_X3.4_SC_UTF8.zip   nginx-1.12.2.tar.gz
mysql-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]# ls
nginx-1.12.2  rh

3,安裝編譯需要的環(huán)境組件包

[root@localhost opt]# yum -y install \
gcc \                    //c語言
gcc-c++ \             //c++語言
pcre-devel \           //pcre語言工具
zlib-devel            //數(shù)據(jù)壓縮用的函式庫

4,創(chuàng)建程序用戶nginx并編譯Nginx

[root@localhost opt]# useradd -M -s /sbin/nologin nginx  ##創(chuàng)建程序用戶,安全不可登陸狀態(tài)
[root@localhost opt]# id nginx
uid=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   ##狀態(tài)統(tǒng)計模塊

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/ 
##創(chuàng)建軟連接讓系統(tǒng)識別nginx啟動腳本

6,制作管理腳本,便于使用service管理使用

[root@localhost nginx]# cd /etc/init.d/  ##切換到啟動配置文件目錄
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx     ##編輯啟動腳本文件

#!/bin/bash
# chkconfig: - 99 20                   ##注釋信息
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"      ##設(shè)置變量為nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid"    ##設(shè)置變量PID文件 進程號為5346
case "$1" in  
         start)
                 $PROG                    ##開啟服務(wù)
                 ;;
         stop)
                 kill -s QUIT $(cat $PIDF)       ##關(guān)閉服務(wù)
                 ;;
         restart)                        ##重啟服務(wù)
                 $0 stop
                 $0 start
                 ;;
         reload)                         ##重載服務(wù)
                 kill -s HUP $(cat $PIDF)
                 ;;
         *)                              ##錯誤輸入提示
                 echo "Usage: $0 {start|stop|restart|reload}"
                exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx   ##給啟動腳本執(zhí)行權(quán)限
[root@localhost init.d]# chkconfig --add nginx      ##添加到service管理器中
[root@localhost init.d]# service nginx stop         ##就可以使用service控制nginx
[root@localhost init.d]# service nginx start

二,隱藏版本號

[root@localhost init.d]# curl -I http://192.168.13.140/  ##查看Nginx信息
HTTP/1.1 200 OK
Server: nginx/1.12.2   ##顯示版本號
Date: Tue, 12 Nov 2019 14:23:24 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 12 Nov 2019 13:46:35 GMT
Connection: keep-alive
ETag: "5dcab7bb-264"
Accept-Ranges: bytes
[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf  ##修改配置文件

http {      ##在http下添加
     include    mime.types;
     default_type  application/octet-stream;
     server_tokens off;   ##關(guān)閉版本號

[root@localhost init.d]# service nginx stop  ##關(guān)閉服務(wù)
[root@localhost init.d]# service nginx start  ##開啟服務(wù)
[root@localhost init.d]# curl -I http://192.168.13.140/  ##查看Nginx信息
HTTP/1.1 200 OK    
Server: nginx       ##版本號被隱藏
Date: Tue, 12 Nov 2019 14:22:00 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 12 Nov 2019 13:46:35 GMT
Connection: keep-alive
ETag: "5dcab7bb-264"
Accept-Ranges: bytes

三,偽造版本號(需要重新編譯安裝,可以在編譯安裝之前操作)

1,開啟版本號

[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf
http {
     include    mime.types;
     default_type  application/octet-stream;
     server_tokens on;  ##開啟版本號

2,修改Nginx源碼包文件

[root@localhost init.d]# cd /opt/nginx-1.12.2/src/core/  ##切換到src源碼包目錄
[root@localhost core]# vim nginx.h  ##修改文件

#define NGINX_VERSION    "1.1.1"  ##此處版本號偽造成1.1.1

3,重新編譯安裝

[root@localhost core]# cd /opt/nginx-1.12.2/   ##切換目錄到Nginx下
[root@localhost nginx-1.12.2]# ./configure \   ##重新配置
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@localhost nginx-1.12.0]# make   ##重新編譯
...
[root@localhost nginx-1.12.0]# make install  ##重新安裝
...

4,重啟Nginx服務(wù),查看版本信息

[root@localhost nginx-1.12.2]# service nginx stop  ##關(guān)閉
[root@localhost nginx-1.12.2]# service nginx start  ##開啟
[root@localhost nginx-1.12.2]# curl -I http://192.168.13.140/  ##查看Nginx信息
HTTP/1.1 200 OK 
Server: nginx/1.1.1    ##此時的版本號就是偽造的版本號
Date: Tue, 12 Nov 2019 14:34:02 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 12 Nov 2019 13:46:35 GMT
Connection: keep-alive
ETag: "5dcab7bb-264"
Accept-Ranges: bytes

Nginx網(wǎng)頁緩存時間

  • 當Nginx將網(wǎng)頁數(shù)據(jù)返回給客戶端后,可設(shè)置緩存時間,以方便在日后進行相同內(nèi)容的請求時直接返回,避免重復請求,加快了訪問速度
  • 一般針對靜態(tài)網(wǎng)頁設(shè)置,對動態(tài)網(wǎng)頁不設(shè)置緩存時間
  • 可在Windows客戶端中使用fiddler查看網(wǎng)頁緩存時間

設(shè)置方法

可修改配置文件,在http段,或者server段,或者location段加入對特定內(nèi)容的過期參數(shù)

實驗環(huán)境

一臺Nginx服務(wù)器
一臺測試機win10

一,將圖片復制到Nginx的站點目錄下

[root@localhost ~]# cd /mnt/  ##切換到掛載點
[root@localhost mnt]# ls
11.jpg          mysql-boost-5.7.20.tar.gz  php-7.1.20.tar.gz
22.jpg          nginx-1.12.2.tar.gz
Discuz_X3.4_SC_UTF8.zip  php-7.1.10.tar.bz2  
[root@localhost mnt]# cp 11.jpg /usr/local/nginx/html/  ##復制圖片到站點中
[root@localhost mnt]# cd /usr/local/nginx/html/   ##切換到站點下
[root@localhost html]# ls
11.jpg  50x.html  index.html

二,修改網(wǎng)頁信息,將圖片加到index.html文件中

[root@localhost html]# vim index.html  ##修改網(wǎng)頁信息

</head>
<body>
<h2>Welcome to nginx!</h2>
<img src="11.jpg"/>  ##加入圖片到網(wǎng)頁中

三,修改配置文件信息

[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf  ##修改配置文件

events {
     worker_connections  1024;
}
     user nginx nginx;   ##修改Nginx用戶和組

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one
   #
   location ~\.(gif|jepg|jpg|ico|bmp|png)$ {   ##支持圖片格式
     root html;   ##站點
     expires 1d;  ##緩存一天
     }
[root@localhost html]# service nginx stop  ##關(guān)閉開啟服務(wù)
[root@localhost html]# service nginx start

四,用fiddler查看緩存

如何隱藏Nginx的版本號
如何隱藏Nginx的版本號

Nginx的日志切割

  • 隨著Nginx運行時間增加,日志也會增加。為了方便掌握Nginx運行狀態(tài),需要時刻關(guān)注日志文件
  • 太大的日志文件對監(jiān)控是一個大災難
    定期進行日志文件的切割
  • Nginx自身不具備日志分割處理的功能,但可以通過Nginx信號控制功能的腳本實現(xiàn)日志的自動切割,并通過Linux的計劃任務(wù)周期性的進行日志切割

1,編寫日志分割腳本文件

[root@localhost ~]# vim fenge.sh  ##編寫腳本文件

#!/bin/bash
#Filename:fenge.sh
d=$(date -d "-1 day" "+%Y%m%d")     ##顯示一天前的時間
logs_path="/var/log/nginx"            ##分割日志的保存路徑
pid_path="/usr/local/nginx/logs/nginx.pid"   ##pid的路徑
[ -d $logs_path ] || mkdir -p $logs_path  ##沒有目錄則創(chuàng)建目錄
mv /usr/local/nginx/logs/access.log ${logs_path}/test.com-access.log-$d
##原有日志文件生成到新路徑下
kill -USR1 $(cat $pid_path)  ##結(jié)束重新生成新的pid文件
find $logs_path -mtime +30 | xargs rm -rf  ##刪除30天前的日志文件

[root@localhost ~]# chmod +x fenge.sh  ##給執(zhí)行權(quán)限
[root@localhost ~]# ./fenge.sh   ##執(zhí)行腳本文件

2,查看日志分割情況

[root@localhost ~]# cd /var/log/nginx/  ##切換到Nginx的日志目錄下
[root@localhost nginx]# ls
test.com-access.log-20191112
[root@localhost nginx]# date -s 2019-11-14  ##修改日期為明天的時間
2019年 11月 14日 星期四 00:00:00 CST
[root@localhost nginx]# cd ~
[root@localhost ~]# ./fenge.sh   ##重新執(zhí)行腳本
[root@localhost ~]# cd /var/log/nginx/
[root@localhost nginx]# ls      ##查看日志分割日志文件
test.com-access.log-20191112  test.com-access.log-20191113

3,設(shè)置周期性計劃任務(wù)

[root@localhost nginx]# crontab -e  ##周期性計劃任務(wù)
0 1 * * * /opt/fenge.sh

關(guān)于隱藏Nginx的版本號的方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞標題:如何隱藏Nginx的版本號-創(chuàng)新互聯(lián)
路徑分享:http://jinyejixie.com/article6/dposog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、網(wǎng)站排名網(wǎng)站維護、自適應網(wǎng)站品牌網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
高尔夫| 陵川县| 贵阳市| 广昌县| 富民县| 石屏县| 仁寿县| 义乌市| 吉水县| 藁城市| 贵阳市| 科技| 遵义县| 洞头县| 宜宾县| 淳安县| 澄城县| 将乐县| 大渡口区| 商城县| 崇文区| 高密市| 古蔺县| 晋州市| 巴彦淖尔市| 专栏| 福建省| 上思县| 理塘县| 南华县| 黔西县| 沂水县| 禹州市| 辽宁省| 辽阳县| 宁河县| 娱乐| 嘉禾县| 苏州市| 尚义县| 庄浪县|