如何限制使用伺服器IP位址存取apache?

如何限制使用伺服器IP位址存取apache?

我有一個伺服器。我在上面安裝並設定了 Virtualmin/Webmin。我還添加了三個網域並配置了幾乎 100% 正確的所有 DNS 記錄。

我的大問題是如何限制透過伺服器 IP 存取網站。或者如何將 IP 從我的伺服器重定向到特定位置以載入特定檔案?

答案1

你應該使用虛擬主機為了那個原因。沿著線條的東西

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/ip_address_root
ServerName 123.123.123.123

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

(範例複製自這裡

或者,模組重寫對此有幫助。就像是

RewriteCond %{REMOTE_HOST}  ^123\.123\.123\.123$
RewriteRule .* http://www.example.org/you_are_using_ip_address [R=301]

答案2

嘗試將 ip 對應到 localhost/etc/主機

相關內容