首先在CentOS7上安裝好nginx服務(wù)之后,可以查看當(dāng)前的nginx版本信息:

[root@localhost init.d]# curl -I http://192.168.234.174 //查看當(dāng)前版本信息
HTTP/1.1 200 OK
Server: nginx/1.12.0 //當(dāng)前的nginx版本信息
Date: Sat, 30 Jun 2018 06:23:15 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 30 Jun 2018 06:17:15 GMT
Connection: keep-alive
ETag: "5b37206b-264"
Accept-Ranges: bytes為了避免版本信息泄露,從而導(dǎo)致不必要的麻煩,下面介紹兩種隱藏版本信息的方法:
修改nginx的主配置文件
[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf
..... 省略
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; //添加關(guān)閉版本顯示重新加載nginx的配置,并且再次查看版本信息
[root@localhost init.d]# service nginx reload //重新加載nginx的配置文件
[root@localhost init.d]# curl -I http://192.168.234.174
HTTP/1.1 200 OK
Server: nginx //這里可以看到當(dāng)前的版本信息已經(jīng)被隱藏起來(lái)了
Date: Sat, 30 Jun 2018 06:35:14 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 30 Jun 2018 06:17:15 GMT
Connection: keep-alive
ETag: "5b37206b-264"
Accept-Ranges: bytes首先修改nginx的源代碼,使別人誤認(rèn)為我們使用的是別的版本
[root@localhost init.d]# vim /opt/nginx-1.12.0/src/core/nginx.h //修改源代碼包
... ...省略
#define nginx_version 1012000
#define NGINX_VERSION "1.12.0" //修改為1.1.1然后進(jìn)行編譯安裝
[root@localhost init.d]# cd /opt/nginx-1.12.0/
[root@localhost nginx-1.12.0]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module //編譯安裝
[root@localhost nginx-1.12.0]# make && make install
[root@localhost conf]# vim nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens on; //開(kāi)啟顯示版本信息
[root@localhost conf]# service nginx stop
[root@localhost conf]# service nginx start //重新啟動(dòng)nginx服務(wù)
[root@localhost conf]# curl -I http://192.168.234.174
HTTP/1.1 200 OK
Server: nginx/1.1.1 //可以看到nginx的版本信息就被篡改了
Date: Sat, 30 Jun 2018 07:03:56 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 30 Jun 2018 06:17:15 GMT
Connection: keep-alive
ETag: "5b37206b-264"
Accept-Ranges: bytes[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
#user nobody; //nobody修改為nginx
nginx;[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
... ... 省略
location / {
root html;
index index.html index.htm;
} //在下面添加
location ~\.(gif|jpg|jepg|png|bmp|ico)$ {
root html;
expires 1d;
}
[root@localhost conf]# cd /usr/local/nginx/html/
[root@localhost html]# cp /abc/Apache/ai.jpg /usr/local/nginx/html/ //復(fù)制一張圖片到html站點(diǎn)的目錄下
[root@localhost html]# service nginx stop
[root@localhost html]# service nginx start //重啟nginx服務(wù)然后此時(shí)使用一臺(tái)安裝了fiddler工具的win7客戶機(jī)去訪問(wèn)nginx服務(wù)器


然后就可以看到這里圖片的緩存時(shí)間已經(jīng)被修改為一天了
[root@localhost ~]# vim /opt/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" #日志的進(jìn)程序列號(hào)
[ -d $logs_path ] || mkdir -p $logs_path
mv /usr/local/nginx/logs/access.log ${logs_path}/test.com-access.log-$d
#將訪問(wèn)日志移動(dòng)到根據(jù)日期每天生成不同的日志文件
kill -USR1 $(cat $pid_path) #中斷日志文件的創(chuàng)建,方便下一次在依次剪切移動(dòng)
find $logs_path -mtime +30 | xargs rm -rf #將30天之前的日志文件刪除
[root@localhost opt]# chmod +x fenge.sh //給與日志分割腳本一個(gè)執(zhí)行權(quán)限
[root@localhost opt]# ./fenge.sh //執(zhí)行腳本
[root@localhost opt]# cd /var/log/nginx/ //查看nginx的日志文件
[root@localhost nginx]# ls
test.com-access.log-20180629 //這里就會(huì)產(chǎn)生一個(gè)前一天的日志文件這里還可以添加為周期性計(jì)劃任務(wù)
[root@localhost nginx]# crontab -e
0 1 * * * /opt/fenge.sh //這樣日志分割任務(wù)就會(huì)周期性的生成,就不需要我們每天都手動(dòng)執(zhí)行一遍腳本了[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf
... ... 省略
#keepalive_timeout 0;
keepalive_timeout 65; //刪除此行,并在下面添加
keepalive_timeout 65 180;
client_header_timeout 80;
client_body_timeout 80;
[root@localhost nginx]# nginx -t //檢查語(yǔ)法
[root@localhost nginx]# service nginx stop
[root@localhost nginx]# service nginx start //重啟nginxfuwu然后此時(shí)同樣使用裝有一臺(tái)安裝了fiddler工具的win7客戶機(jī)去訪問(wèn)nginx服務(wù)器


首先在進(jìn)行防盜鏈配置時(shí),我們要先準(zhǔn)備兩臺(tái)win7客戶機(jī)(網(wǎng)卡模式是NAT,IP地址自動(dòng)獲取),一臺(tái)(win7)進(jìn)行盜鏈操作,另一臺(tái)(win7-1)做訪問(wèn)端
開(kāi)始進(jìn)行盜用鏈接配置,首先盜鏈端(win7)開(kāi)啟IIS服務(wù),并且寫入一個(gè)首頁(yè)內(nèi)容
<html>
<head></head>
<body>
<h2>this is test!!!</h2> //首頁(yè)內(nèi)容
<img src="/upload/otherpic41/game.jpg"> //進(jìn)行盜鏈的網(wǎng)站和圖片
</body>
</html>然后在CentOS7上安裝DNS服務(wù),并且修改配置
[root@localhost nginx]# yum install bind -y
[root@localhost nginx]# vim /etc/named.conf //修改主配置文件
listen-on port 53 { 127.0.0.1; }; //127.0.0.1修改為any
allow-query { localhost; }; //localhost修改為any
[root@localhost nginx]# vim /etc/named.rfc1912.zones //修改區(qū)域配置文件
//添加下面的配置
zone "benet.com" IN {
type master;
file "benet.com.zone";
allow-update { none; };
};
zone "test.com" IN {
type master;
file "test.com.zone";
allow-update { none; };
};
[root@localhost nginx]# cd /var/named/
[root@localhost named]# cp -p named.localhost benet.com.zone
[root@localhost named]# vim benet.com.zone //修改區(qū)域數(shù)據(jù)庫(kù)文件
刪除末行,添加
www IN A 192.168.234.174 //解析指向nginx服務(wù)器的IP
[root@bogon named]# cp -p benet.com.zone test.com.zone
[root@localhost named]# vim test.com.zone
修改末行的www 后的解析地址,指向盜鏈服務(wù)器的IP,即
www IN A 192.168.234.180 //這里是win7的IP這里盜鏈的操作就完成了,我們可以看下效果
訪問(wèn)www.test.com

訪問(wèn)www.benet.com

接下來(lái)配置防盜鏈配置
[root@bogon html]# vim /usr/local/nginx/conf/nginx.conf
... ...省略 添加//
location ~*\.(jpg|gif|swf)$ {
valid_referers none blocked *.benet.com benet.com;
if ( $invalid_referer ) {
rewrite ^/ /upload/otherpic41/error.png;
}
}
[root@bogon named]# cd /usr/local/nginx/html/
[root@bogon html]# cp /abc/LNMP/error.png ./ //添加一張重定向的圖片
[root@bogon html]# service nginx stop
[root@bogon html]# service nginx start //重啟nginx服務(wù)防盜鏈操作完成后,我們?cè)趤?lái)使用win7-1客戶機(jī)訪問(wèn)查看效果(訪問(wèn)前先清空緩存):
訪問(wèn)www.test.com

訪問(wèn)www.benet.com

這樣防盜鏈就完成了。
以上就是CentOS7上nginx的所有優(yōu)化配置了,請(qǐng)各位看官多多點(diǎn)評(píng)與點(diǎn)贊!!!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
名稱欄目:基于CentOS7上的nginx系統(tǒng)優(yōu)化-創(chuàng)新互聯(lián)
本文路徑:http://www.yijiale78.com/article0/pssoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、App開(kāi)發(fā)、軟件開(kāi)發(fā)、品牌網(wǎng)站建設(shè)、建站公司、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容