綠色資源網(wǎng):您身邊最放心的安全下載站! 最新軟件|熱門排行|軟件分類|軟件專題|論壇轉(zhuǎn)帖|廠商大全

綠色資源網(wǎng)

技術(shù)教程
您的位置:首頁服務器類Linux服務器 → Linux系統(tǒng)下,如何禁用Apache和nginx的空主機頭

Linux系統(tǒng)下,如何禁用Apache和nginx的空主機頭

我要評論 2013/01/09 19:55:30 來源:綠色資源網(wǎng) 編輯:sonlywya.cn [ ] 評論:0 點擊:701次

為了防止域名解析惡意指向,我們需要禁止apache默認的空主機頭,操作如下:

vi /etc/httpd/conf/httpd.conf
編輯配置文件,在你的站點配置之前再增加一個站點(紅色字體部分是我們要增加的,藍色字體部分代表你正在使用的站點配置)

NameVirtualHost *
<VirtualHost *:80>
ServerAdmin yourmail#mail.com
DocumentRoot /error
ServerName abc.com
</VirtualHost>


<VirtualHost *:80>
ServerAdmin yourmail#mail.com
DocumentRoot "你的站點路徑"
ServerName yourWebsite.com
ServerAlias *.yourWebsite.com
</VirtualHost>


Linux系統(tǒng)下禁止nginx空主機頭
引言:為了防止域名解析惡意指向,我們需要禁止nginx默認的空主機頭,操作如下
vi /usr/local/nginx/conf/nginx.conf    #配置文件
找到server,添加下面這兩行:
listen 80 default;        #default代表默認虛擬主機
server_name _;
例如:
server {
listen 80 default;
server_name _;
return 500;   #返回500錯誤信息
}
還可以把這些空的流量轉(zhuǎn)向到某一個網(wǎng)站,如下設(shè)置:
server {
listen 80 default;
server_name _;
rewrite ^(.*) http://某個網(wǎng)址 permanent;    #頁面重定向
}

關(guān)鍵詞:Linux,Apache,nginx

閱讀本文后您有什么感想? 已有 人給出評價!

  • 0 歡迎喜歡
  • 0 白癡
  • 0 拜托
  • 0 哇
  • 0 加油
  • 0 鄙視