On May 18, 2016, at 1:06 AM, 王冠 <wgwg1...@gmail.com> wrote:
我有一台机器,上面运行了 openvpn 服务和 nginx 服务。现在希望外网的设备在连接上 vpn 的时候能访问 nginx 没有连接上 vpn 的时候不能访问 nginx。不知道该怎么设置才好,现在的情况是由于是同一台机器上运行的两个服务,所以就算外网的设备连接上了 vpn 但是它访问 nginx 的时候不会走 vpn 通道,而是采用直接连接的方式。
--
来自USTC LUG
请使用gmail订阅,不要灌水。
更多信息more info:http://groups.google.com/group/ustc_lug?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "USTC_LUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ustc_lug+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
感觉像是我没有说清楚,具体的情况是这样的,nginx 本身是对公网服务的,但是网站的后台我在nginx 上设置的是只能通过内网 ip 访问。location /wp-admin {allow 10.0.0.0/8;allow 192.168.0.0/16;deny all;proxy_pass http://server-ip$request_uri;proxy_set_header Accept-Encoding "";proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-Proto https;}
对啊,不就是这样子的么?就是不知道还能怎么解决,除了在DNS上面加一个内网地址!
如果你的 VPN 是全局 VPN,也就是连上 VPN 之后到所有 IP 的流量都走 VPN,VPN 服务器上做 SNAT 转发,那么不修改 DNS 也是可以解决的。第一种方法,nginx 服务器上检查源 IP 为 VPN 服务器的公网 IP。第二种方法,VPN 服务器上增加 iptables DNAT 规则,把发往 www.example.com 公网 IP 的数据包 DNAT 到内网 IP,nginx 服务器上检查源 IP 为内网 IP 段。如果你的 VPN 连接上之后只对内网流量走 VPN,那就只能修改 DNS 了。这种情况下,最简单的方法是用另一个域名作为管理地址(例如 admin.example.com),以免与主域名的 DNS 混淆。如果你能够保证连上 VPN 之后使用内网自建的 DNS 服务器,当然也可以在内网自建 DNS 上对该域名返回内网 IP,这也是大多数家庭网关的做法。