您拥有一台具有公共 IP 的服务器,并且 apache 正在其上运行。现在您希望在 LAN 上托管您的应用程序,并且还希望它们可以通过 Internet 访问,重要的是这些应用程序仍然在 LAN 上的计算机上运行。
|--------------192.168.1.3
| (internal3.example.com)
|
|--------------192.168.1.4
| (internal4.example.com)
(Public IP ) |
A--------------|
(reverse proxy server) |
(192.168.1.25) |
example.com |
|--------------192.168.1.1
| (internal1.example.com)
|
|--------------192.168.1.2
| (internal2.example.com)
我正在使用 Ubuntu 来托管 Apache,如果是基于 Debian 的系统,则虚拟主机定义是在其上完成的
/etc/apache2/sites-enabled/*.conf
其中 *conf 对应于
内部1.conf 内部2.conf 内部3.conf 内部4.conf
每个站点的虚拟主机定义如下
/etc/apache2/sites-enabled/internal1.example.conf
<virtualhost *:80>
ServerAdmin webmaster@localhost
ServerName internal1.example.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy >
ProxyPass / http://192.168.1.1/
ProxyPassReverse / http://192.168.1.1/
</VirtualHost>
/etc/apache2/sites-enabled/internal2.example.conf
<virtualhost *:80>
ServerAdmin webmaster@localhost
ServerName internal2.example.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy >
ProxyPass / http://192.168.1.2/
ProxyPassReverse / http://192.168.1.2/
</VirtualHost >
/etc/apache2/sites-enabled/internal3.example.conf
<virtualhost *:80>
ServerAdmin webmaster@localhost
ServerName internal3.example.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy >
ProxyPass / http://192.168.1.3/
ProxyPassReverse / http://192.168.1.3/
</VirtualHost >
/etc/apache2/sites-enabled/internal4.example.conf
<virtualhost *:80>
ServerAdmin webmaster@localhost
ServerName internal4.example.com
ProxyRequests off
<proxy *>
Order deny,allow
Allow from all
</proxy>
ProxyPass / http://192.168.1.4/
ProxyPassReverse / http://192.168.1.4/
</VirtualHost>
请注意,在上述所有虚拟主机定义中,我删除了日志文件的选项。
因此,如果您应用于生产服务器,请将它们添加到每个 vhost 文件中。
上面只是给您一个清晰的示例来说明它是如何工作的。
我运行了一个非常复杂的 Apache 设置,所以上面只是一个小例子来帮助您。
现在来谈谈你问题的Ajax部分
在 chrome 中按 Ctrl+Shift+I 您将看到应用程序到底在哪里损坏,
它会给你一些线索,(从与您正在开发 Web 应用程序的计算机不同的计算机发出请求)
另外,如果您可以查看 apache 日志,如果请求来自http://sample
具有 ajx api 的页面实际上到达了您的 apache 服务器,这将为您提供更多提示,如果代理正确转发您的请求,请使用 firefox 中的某些工具(如 live_http)发布 HTTP 标头,在没有请求时的情况下以及在没有请求时的情况下请求是由应用程序发出的,通过这种方式观察标头可以帮助您确定请求是否到达了反向代理后面的服务器,还可以检查运行反向代理的服务器的日志是否来自网络的请求到达了它,以及该请求是否到达了该服务器。到达所请求的 URL 是什么。这将为您提供线索,
出于开发目的,在您的 .conf 文件中禁用重写规则一段时间以进行测试,一一进行。