.htaccess - 只允许通过 VPN 私有(private)访问网站

我知道这可能是非常基本的,但我的服务器上有一个网站,我只想通过 VPN 访问它。我的 Windows 机器上运行着 OpenVPN,它通过 VPN 连接到我的服务器。当 VPN 连接时,我可以使用 VPN 的 IP 地址访问我服务器上的站点。我想阻止所有其他方法,例如实际站点 IP 或我的域名。我会使用 htaccess 吗?通常只为私有(private)访问所做的事情。

最佳答案

假设你的服务器 vpn ip 是 10.1.2.3 那么你应该添加到你的 apache 配置中

Listen 10.1.2.3:80

这样您将绑定(bind) Apache - 即接受传入请求 - 仅到该地址。

还有:

The Listen directive does not implement Virtual Hosts - it only tells the main server what addresses and ports to listen on. If no directives are used, the server will behave in the same way for all accepted requests. However, can be used to specify a different behavior for one or more of the addresses or ports. To implement a VirtualHost, the server must first be told to listen to the address and port to be used. Then a section should be created for the specified address and port to set the behavior of this virtual host. Note that if the is set for an address and port that the server is not listening to, it cannot be accessed.

即你可以保留原来的监听指令(监听所有接口(interface))并过滤每个虚拟主机的访问,你的“私有(private)”虚拟主机配置如下:

<VirtualHost 10.1.2.3:80>

参见 http://httpd.apache.org/docs/2.4/bind.html

最后,如果由于某种原因你只能使用 .htaccess,那么你可以在 .htaccess 中做:

Order Deny,Allow
Deny from all
Allow from 10.1.2.1/24

即只允许从您的 vpn 子网访问。

请注意,每次更改后都需要重新启动网络服务器。

https://stackoverflow.com/questions/35427321/

相关文章:

amazon-web-services - 更新和部署 Elastic Beanstalk 应用程序

visual-studio - 如何在 Google Chrome 扩展程序中创建侧边栏?

asp.net-mvc - ASP.net MVC : Identity and drop auth

ruby-on-rails - 如何连接表以仅获取 has-many 关联的最后一条记录?

angularjs - UI-Grid 分页模板可编辑

sql - Knex 原始查询不工作 postgresql

vim - tmux 将选择从复制模式发送到其他 Pane (xargs 加入?)

oracle - 安装 Oracle ODAC 12c 第 4 版 (12.1.0.2.4) 时出现

turing-machines - PCP 可以识别吗?

html-table - 在单个表格行 中混合表格标题 和表格数据 单