问:我想限制对我网站的直接 IP 访问。我找到了几个涉及 .htaccess 的解决方案,但都没有o。用。
答:在httpd的末尾添加下面设置:
<VirtualHost mysite.com:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /home/rotate/public_html
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
UseCanonicalName Off
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName 192.168.1.1
Redirect 403 /
ErrorDocument 403 "Sorry, direct IP access not allowed."
DocumentRoot /usr/local/apache/htdocs
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
UseCanonicalName Off
UserDir disabled
</VirtualHost>
<VirtualHost *>
ServerName server.mysite.com
DocumentRoot /usr/local/apache/htdocs
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
UserDir disabled
</VirtualHost>
<VirtualHost mysite.com:443>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /home/rotate/public_html
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
UseCanonicalName Off
</VirtualHost>
这个解决方案可以简单地将所有虚拟主机设置的 IP 替换为域名。