Wishlist 0 ¥0.00

apache如何禁止访问者直接通过网站的 IP 访问网站?

问:我想限制对我网站的直接 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 替换为域名。

About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.