首页 > 解决方案 > 仅在服务器中限制对本地地址的访问

问题描述

我在服务器中有多个 Web 应用程序系统,可以使用 122.0.0.1 通过互联网访问。我想使用 192.0.0.0 仅在没有 Internet 连接的情况下访问 localhost/network 中的一个系统。

例如:122.0.0.0/abc 122.0.0.0/def 122.0.0.0/ghi 可以通过互联网访问。但我不想通过互联网访问 122.0.0.0/abc。我想通过 LAN 使用 196.0.0.0/abc 在线访问它。

这可能吗?那怎么办?

谢谢你。

标签: mysqlcodeigniter

解决方案


在您的 .htaccess 文件中,您可以添加这些行以仅允许特定的 IP 地址:

Order Deny,Allow
Deny from all
Allow from YourIPAdress

您也可以使用此方法,将其包含在您的 .htaccess 或虚拟主机配置文件中:

这里提到:https ://stackoverflow.com/a/23325758/1993548

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxy [OR]
    RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxz
    RewriteRule .* - [L] #do notthing

    #if we are here, the IP is not in the allowed list, redirect
    RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
    RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

推荐阅读