如何阻止對我的 Web 伺服器的直接 IP 存取而不回應錯誤代碼?

如何阻止對我的 Web 伺服器的直接 IP 存取而不回應錯誤代碼?

我希望人們能幫助我解決這個問題。

例子:

我的網域是:example.com

我的 IP 位址是 103.103.103.103

當人們嘗試在連接埠 80 上連接到我的 IP 時。

它應該顯示:正在連接(在瀏覽器上)...沒有回應。

我嘗試修改httpd.conf(我使用apache 2.4)但尚未成功。

我嘗試谷歌搜索,但我的問題沒有結果。

謝謝

答案1

假設您希望請求http://example.com為您的網站提供服務,並要求http://103.103.103.103據我所知,要明確刪除,您有兩個主要選擇。

1)是使用模組安全模組和drop目標。像這樣的配置;

    <VirtualHost *:80>
        ServerName default.only
        SecRuleEngine On
        SecRule REMOTE_ADDR "^\d" id:'1234',drop,phase:1
    </VirtualHost>

    <Directory /var/www/example.com >
      Options FollowSymLinks
      AllowOverride FileInfo Options
      Order allow,deny
      Allow from all
    </Directory>

    <VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/example.com
    </VirtualHost>

返回網站,如果您訪問http://example.com

# wget -O-  http://example.com
--2018-03-09 15:35:35--  http://example.com/
Resolving example.com (example.com)... 127.0.0.1
Connecting to example.com (example.com)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24 [text/html]
Saving to: ‘STDOUT’

如果您嘗試透過 ip 存取預設站點http://127.0.0.1

# wget -O-  http://127.0.0.1
--2018-03-09 15:35:28--  http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... No data received.

連線已斷開

2) 第二種選擇是使用該string模組iptables並刪除與標頭相符的連接Host: 103.103.103.103

iptables -A INPUT -m string --string "Host: 103.103.103.103" -j DROP

(我沒有測試 iptables 規則...所以你必須檢查文件以獲得正確的咒語...)但是我認為 mod_security 選項更簡單

相關內容