這可以通過使用腳本來實現(修改以滿足您的需要):
#!/bin/bash
# Dynamic IP .htaccess file generator
# Written by Star Dot Hosting
# www.stardothosting.com
dynDomain="$1"
htaccessLoc="$2"
dynIP=$(/usr/bin/dig +short $dynDomain)
echo "dynip: $dynIP"
# verify dynIP resembles an IP
if ! echo -n $dynIP | grep -Eq "[0-9.]+"; then
exit 1
fi
# if dynIP has changed
if ! cat $htaccessLoc | /bin/grep -q "$dynIP"; then
# grab the old IP
oldIP=`cat /usr/local/bin/htold-ip.txt`
# output .htaccess file
echo "order deny,allow" > $htaccessLoc 2>&1
echo "allow from $dynIP" >> $htaccessLoc 2>&1
echo "allow from x.x.x.x" >> $htaccessLoc 2>&1
echo "deny from all" >> $htaccessLoc 2>&1
# save the new ip to remove next time it changes, overwriting previous old IP
echo $dynIP > /usr/local/bin/htold-ip.txt
fi
不僅僅是它和cron上產生.htaccess文件新的一行:
*/15 * * * * /bin/sh /usr/local/bin/.sh yourhostname.no-ip.org /var/www/folder/.htaccess > /dev/null 2>&1
來源:https://www.stardothosting.com
爲duskwuff指出,沒有IP不利於爲客戶域名沒有在HTTP使用,也沒有辦法爲你的服務器知道它(除了反向DNS這並不適用於DYN amic IPs)。 – Sandman4 2012-08-06 08:38:07