最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Nginx隱藏版本號(hào)的方法

 更新時(shí)間:2019年11月19日 14:24:27   作者:wx5d3a7feeb53cc  
這篇文章主要介紹了Nginx隱藏版本號(hào)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

Nginx隱藏版本號(hào)

在生產(chǎn)環(huán)境中,需要隱藏Nginx的版本號(hào),以避免安全漏洞的泄露

查看方法

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

Nginx隱藏版本號(hào)的方法

修改配置文件法
修改源碼法

一,安裝Nginx

1,在Linux上使用遠(yuǎn)程共享獲取文件并掛載到mnt目錄下

[root@localhost ~]# smbclient -L //192.168.100.3/  ##遠(yuǎn)程共享訪問(wèn)
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  ##切換到掛載點(diǎn)目錄
[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語(yǔ)言
gcc-c++ \            //c++語(yǔ)言
pcre-devel \           //pcre語(yǔ)言工具
zlib-devel            //數(shù)據(jù)壓縮用的函式庫(kù)

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)計(jì)模塊

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)識(shí)別nginx啟動(dòng)腳本

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

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

#!/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文件 進(jìn)程號(hào)為5346
case "$1" in 
        start)
                $PROG                   ##開(kāi)啟服務(wù)
                ;;
        stop)
                kill -s QUIT $(cat $PIDF)      ##關(guān)閉服務(wù)
                ;;
        restart)                        ##重啟服務(wù)
                $0 stop
                $0 start
                ;;
        reload)                        ##重載服務(wù)
                kill -s HUP $(cat $PIDF)
                ;;
        *)                              ##錯(cuò)誤輸入提示
                echo "Usage: $0 {start|stop|restart|reload}"
               exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx  ##給啟動(dòng)腳本執(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

二,隱藏版本號(hào)

[root@localhost init.d]# curl -I http://192.168.13.140/  ##查看Nginx信息
HTTP/1.1 200 OK
Server: nginx/1.12.2  ##顯示版本號(hào)
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)閉版本號(hào)

[root@localhost init.d]# service nginx stop ##關(guān)閉服務(wù)
[root@localhost init.d]# service nginx start ##開(kāi)啟服務(wù)
[root@localhost init.d]# curl -I http://192.168.13.140/ ##查看Nginx信息
HTTP/1.1 200 OK   
Server: nginx      ##版本號(hào)被隱藏
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

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

1,開(kāi)啟版本號(hào)

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

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" ##此處版本號(hào)偽造成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 ##開(kāi)啟
[root@localhost nginx-1.12.2]# curl -I http://192.168.13.140/  ##查看Nginx信息
HTTP/1.1 200 OK 
Server: nginx/1.1.1    ##此時(shí)的版本號(hào)就是偽造的版本號(hào)
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)頁(yè)緩存時(shí)間

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

設(shè)置方法

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

實(shí)驗(yàn)環(huán)境

一臺(tái)Nginx服務(wù)器
一臺(tái)測(cè)試機(jī)win10

一,將圖片復(fù)制到Nginx的站點(diǎn)目錄下

[root@localhost ~]# cd /mnt/  ##切換到掛載點(diǎn)
[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/  ##復(fù)制圖片到站點(diǎn)中
[root@localhost mnt]# cd /usr/local/nginx/html/  ##切換到站點(diǎn)下
[root@localhost html]# ls
11.jpg 50x.html index.html

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

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

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

三,修改配置文件信息

[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;   ##站點(diǎn)
    expires 1d;  ##緩存一天
    }
[root@localhost html]# service nginx stop  ##關(guān)閉開(kāi)啟服務(wù)
[root@localhost html]# service nginx start 

四,用fiddler查看緩存


Nginx的日志切割

隨著Nginx運(yùn)行時(shí)間增加,日志也會(huì)增加。為了方便掌握Nginx運(yùn)行狀態(tài),需要時(shí)刻關(guān)注日志文件

太大的日志文件對(duì)監(jiān)控是一個(gè)大災(zāi)難

定期進(jìn)行日志文件的切割

Nginx自身不具備日志分割處理的功能,但可以通過(guò)Nginx信號(hào)控制功能的腳本實(shí)現(xiàn)日志的自動(dòng)切割,并通過(guò)Linux的計(jì)劃任務(wù)周期性的進(jìn)行日志切割

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

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

#!/bin/bash
#Filename:fenge.sh
d=$(date -d "-1 day" "+%Y%m%d")    ##顯示一天前的時(shí)間
logs_path="/var/log/nginx"           ##分割日志的保存路徑
pid_path="/usr/local/nginx/logs/nginx.pid"  ##pid的路徑
[ -d $logs_path ] || mkdir -p $logs_path ##沒(méi)有目錄則創(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 ##修改日期為明天的時(shí)間
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è)置周期性計(jì)劃任務(wù)

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nginx服務(wù)狀態(tài)監(jiān)控的方法

    Nginx服務(wù)狀態(tài)監(jiān)控的方法

    這篇文章主要介紹了Nginx服務(wù)狀態(tài)監(jiān)控的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • 詳解Nginx 虛擬主機(jī)配置的三種方式(基于端口)

    詳解Nginx 虛擬主機(jī)配置的三種方式(基于端口)

    Nginx配置虛擬主機(jī)支持3種方式主要有基于IP的虛擬主機(jī)配置,基于端口的虛擬主機(jī)配置,基于域名的虛擬主機(jī)配置。本篇文章主要介紹了基于端口的實(shí)現(xiàn),感興趣的小伙伴們可以參考一下
    2018-10-10
  • Nginx配置二級(jí)域名的方法實(shí)現(xiàn)

    Nginx配置二級(jí)域名的方法實(shí)現(xiàn)

    本文主要介紹了Nginx配置二級(jí)域名的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • nginx常用命令放入shell腳本詳解

    nginx常用命令放入shell腳本詳解

    這篇文章主要介紹了nginx常用命令放入shell腳本詳解,文章講解的很清晰,有感興趣的同學(xué)可以研究下
    2021-02-02
  • nginx 目錄密碼保護(hù)的設(shè)置方法

    nginx 目錄密碼保護(hù)的設(shè)置方法

    比如要對(duì) 網(wǎng)站目錄下的 test 文件夾 進(jìn)行加密認(rèn)證
    2010-12-12
  • Nginx服務(wù)器中為網(wǎng)站或目錄添加認(rèn)證密碼的配置詳解

    Nginx服務(wù)器中為網(wǎng)站或目錄添加認(rèn)證密碼的配置詳解

    這篇文章主要介紹了Nginx服務(wù)器中為網(wǎng)站或目錄添加認(rèn)證密碼的配置詳解,使用到了Apache的htpasswd工具,需要的朋友可以參考下
    2016-01-01
  • nginx如何限制訪問(wèn)某些url

    nginx如何限制訪問(wèn)某些url

    這篇文章主要關(guān)于介紹了nginx如何限制訪問(wèn)某些url的相關(guān)資料,nginx是非常出色web服務(wù)器,對(duì)于靜態(tài)文件的處理非常高效,同時(shí)它的代理轉(zhuǎn)發(fā)功能和其它后臺(tái)服務(wù)器搭配起來(lái)也非常的簡(jiǎn)單高效,需要的朋友可以參考下
    2023-08-08
  • 生產(chǎn)環(huán)境之Nginx高可用方案實(shí)現(xiàn)過(guò)程解析

    生產(chǎn)環(huán)境之Nginx高可用方案實(shí)現(xiàn)過(guò)程解析

    這篇文章主要介紹了生產(chǎn)環(huán)境之Nginx高可用方案實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • 解決nginx 503 Service Temporarily Unavailable方法示例

    解決nginx 503 Service Temporarily Unavailable方法示例

    這篇文章主要介紹了解決nginx 503 Service Temporarily Unavailable方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • nginx中g(shù)zip壓縮提升網(wǎng)站速度的實(shí)現(xiàn)方法

    nginx中g(shù)zip壓縮提升網(wǎng)站速度的實(shí)現(xiàn)方法

    這篇文章主要介紹了nginx中g(shù)zip壓縮提升網(wǎng)站速度的實(shí)現(xiàn)方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08

最新評(píng)論

扎鲁特旗| 尉犁县| 凉山| 旅游| 上饶市| 嫩江县| 桂平市| 威宁| 邵阳县| 临沧市| 龙江县| 广水市| 九龙县| 类乌齐县| 长泰县| 梅州市| 张家口市| 娄底市| 凯里市| 尼木县| 石棉县| 宣恩县| 滕州市| 镇赉县| 克什克腾旗| 清苑县| 博湖县| 老河口市| 剑阁县| 偃师市| 台湾省| 承德县| 沾益县| 保康县| 宁河县| 丹江口市| 三门县| 稻城县| 浮山县| 舞阳县| 柞水县|