只允许通过 VPN 私人访问网站

Only allow private access to website through VPN

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

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

Listen 10.1.2.3:80

以便您将绑定 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.

即你可以保留原来的监听指令(监听所有接口)并过滤每个虚拟主机的访问,你的 "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 子网访问。

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