如何反向代理子域到我的局域网上的另一台计算机,在OS X服务器?

可视化这个结果:

  1. site1.example.com – >我的单个公共IP – >端口转发80和443到LAN 192.168.1.10OS X上运行OS X Server 4.1的Mac 10.10优胜美地
  2. site2.example.com – >我的单个公共IP – >局域网192.168.1.10 – >反向代理? – >:80和:443在局域网192.168.1.15

这是在一个networking,我没有select添加另一个公共IP。

#1已经正常运行。

#2是最难的部分,主要是因为我在#1上运行OS X Server ,而代理设置似乎并不是相对直接的Apache ,例如:

 <VirtualHost *:80 *:443> ServerName site2.example.com ProxyRequests off ProxyPass / http://192.168.1.15/ ProxyPassReverse / http://192.168.1.15/ </VirtualHost> 

也就是说,OS X服务器在奇怪的地方有Apacheconfiguration文件,我的理解是,它喜欢用在GUI中做出的新更改覆盖它们,所以我试图找出“正确”的方式来做到这一点OS X服务器。

我的一位朋友build议,尽pipeOS X Server文档的Web应用程序部分几乎不包含任何细节,但可能有办法使用OS X Server的webappctl命令并编写适当的webapp.plist 。 看着苹果build议的man页和他们的示例.plist文件,在我看来,他们的“networking应用程序”的想法真的要连接到一个目录(即site1.example.com/webapp),而不是一个子域(如上面#2所示)。 也许我只是不完全想出了.plist格式呢?

什么是在OS X服务器上执行此操作的“正确”方法?

我认为你的朋友可能正在使用webappctlpath。 但是让我们从Apache开始吧:当使用OS X Server时,Apache从/Library/Server/Web/Config/apache2 。 该目录包含一个文件ReadMe.txt ,部分说明如下:

网站/

该目录包含服务器应用程序为“网站服务”configuration的每个启用的虚拟主机的文件。 由于httpd_server_app.conf中有多个“Include”指令,Apache的内容被Apache读取。

这些文件由服务器应用程序的服务器驻留部分和webappctl(8)修改。 pipe理员可以直接对这个文件和定制的虚拟主机文件进行修改,但是强烈build议pipe理员把修改放在单独的“包含”文件中,并将webapp.plist(8)机制和webappctl(8)线工具来pipe理它们。 请参阅这些文件顶部的编辑指南。

好吧,似乎是合理的。 进一步查看Apacheconfiguration目录,还有引用的sites子目录以及webapps 。 后者包含一堆描述OS X Server的Web服务的plists,另外一个名为com.example.mywebapp.plist 。 在该文件的顶部,有一些有趣的地方:

  • includeFiles键,它看起来有一个path数组,用于定制web应用程序需要的.conf文件
  • proxies键,映射到另一个应用程序的Apache ProxyPass / ProxyPassReverse指令

虽然我没有自己testing过,但是我的build议可能是尝试使用相同的反向DNS命名scheme来添加plist到这个目录:将com.example.mywebapp.plist复制到com.example.site2.plist 。 一旦你有自己的副本,你可以砍掉大部分不必要的位,然后调整proxies值来引用你自己的URL,而不是他们拥有的示例path。

如果这不起作用,你可以应用一个稍微大一些的锤子,创build一个includable.conf文件,该文件包含你的直接的Apache指令,放在Server的Apacheconfiguration目录中。 完成之后,从您的webapp plist中完全删除proxies密钥,然后使用includeFiles键来获取.conf文件。

无论哪种方式,一旦webapp plist到位,使用webappctl (作为根)来启动新创build的应用程序:

$ sudo webappctl start com.example.site2

这应该要么成功(返回退出代码0),或者 – 希望 – 与一些信息,你可以提炼的webapp plist失败。 (同样,这一切都没有经过testing,只是从一开始。)

如果你确实使用了一个自定义的.conf文件,你从webapp plist中引用,那么在某个地方保存该文件的备份也是一个不错的主意,以便将来的OS X或Server.app更新不会擦除它。 虽然服务器的Apache ReadMe.txt并没有明确说明它们清除用户生成的configuration,但是也不会说它们不会 。 比对不起更安全。

祝你好运!

这个问题最初是关于Mac OS X Server 4.1问的,但是随着软件版本号的提升,我刚刚得到了这个工作,这个答案是从macOS Server 5.2开始编写的。 服务器5显然改变了一点,因为服务器中的每个服务现在都在一个主反向代理之后,所以这些指令在Server 4.1中不起作用。

configuration文件

/Library/Server/Web/Config/apache2/httpd_site2webapp.conf ,在macOS服务器机器上创buildWeb应用程序configuration文件,指向site2服务器的IP地址。

 ProxyPreserveHost On ProxyPassReverse / http://192.168.1.15:80/ ProxyPass / http://192.168.1.15:80/ ServerName site2.example.com 

然后在/Library/Server/Web/Config/apache2/webapps/com.example.site2webapp.plist中添加以下内容,引用上面的.conf文件的位置:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!-- See man pages for webapp.plist(5) and webappctl(8) for information about this example webapp.plist --> <plist version="1.0"> <dict> <key>includeFiles</key> <array> <!-- Include files are activated in virtual host when webapp is started --> <string>/Library/Server/Web/Config/apache2/httpd_site2webapp.conf</string> </array> <key>name</key> <string>com.example.site2webapp</string> <key>displayName</key> <!-- Name shown in Server app --> <string>site2WebApp</string> <key>installationIndicatorFilePath</key> <!-- The presence of this file indicates web app is installed --> <string>/Library/Server/Web/Config/apache2/httpd_site2webapp.conf</string> <key>sslPolicy</key><!-- Determines webapp SSL behavior --> <integer>0</integer> <!-- 0: default, UseSSLWhenEnabled --> <!-- 1: UseSSLAlways --> <!-- 2: UseSSLOnlyWhenCertificateIsTrustable --> <!-- 3: UseSSLNever --> <!-- 4: UseSSLAndNonSSL --> </dict> </plist> 

如果您还需要SSL,请将以下内容放在/Library/Server/Web/Config/apache2/httpd_site2SSLwebapp.conf 。 configuration不同,默认情况下服务器之间的LANstream量将不encryption(这个configuration实际上告诉服务器不检查是否有有效的证书),但WANstream量将被encryption。 我相信您可以在site2服务器上安装一个自签名证书来encryption本地stream量,但是此configuration仍然可以启用反向代理,而不必具有匹配的证书。 (我承认可能有一个更正确的方法来保证当地的stream量,但是这对我有效。)

 SSLProxyEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off ProxyPreserveHost On ProxyPassReverse / http://192.168.1.15:80/ ProxyPass / http://192.168.1.15:80/ ServerName site2.example.com 

和相应的SSL Web应用程序plist /Library/Server/Web/Config/apache2/webapps/com.example.site2SSLwebapp.plist ,与上面的内容大致相同:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!-- See man pages for webapp.plist(5) and webappctl(8) for information about this example webapp.plist --> <plist version="1.0"> <dict> <key>includeFiles</key> <array> <!-- Include files are activated in virtual host when webapp is started --> <string>/Library/Server/Web/Config/apache2/httpd_site2SSLwebapp.conf</string> </array> <key>name</key> <string>com.example.site2SSLwebapp</string> <key>displayName</key> <!-- Name shown in Server app --> <string>site2SSLWebApp</string> <key>installationIndicatorFilePath</key> <!-- The presence of this file indicates web app is installed --> <string>/Library/Server/Web/Config/apache2/httpd_site2SSLwebapp.conf</string> <key>sslPolicy</key><!-- Determines webapp SSL behavior --> <integer>0</integer> <!-- 0: default, UseSSLWhenEnabled --> <!-- 1: UseSSLAlways --> <!-- 2: UseSSLOnlyWhenCertificateIsTrustable --> <!-- 3: UseSSLNever --> <!-- 4: UseSSLAndNonSSL --> </dict> </plist> 

对于这四个文件中的每一个,权限都必须是所有者:root和group:wheel,644:

 $ sudo chown -R root:wheel /path/to/file $ sudo chmod -R 644 /path/to/file 

设置Server.app

添加网页应用程序到网站

  • 在Server.app界面的网站选项卡中,单击网站列表下方的+添加新站点
  • 为域名inputsite2.example.com
  • 将所有其他设置保留为默认设置
  • 点击编辑高级设置…
  • 在“在这个网站上提供这些Web应用程序:”部分的下面,选中为site2WebApp启用
  • 点击OK
  • 点击创build

SSL

如果您在广域网上需要SSL,请在服务器中安装涵盖新域的证书。 我使用Let's Encrypt来创build一个对我的site1site2都有好处的证书。

  • 在Server.app的证书选项卡中,单击窗口底部的+ ,然后导入证书标识…
  • 拖放从Let's Encrypt(或您拥有的任何证书文件)中获得的.pem文件,然后单击导入
  • 在“ 网站”选项卡中,创build与以前几乎相同的新网站,除了将“端口”更改为443以及在“SSL证书”下,select刚导入的证书
  • 编辑高级设置…下 ,select启用site2SSLWebApp

我的回答是根据https://www.precursor.ca/precursor/resources/rais/landing/ReverseProxyTutorial.html上的说明改编的&#x3002; 警告:此链接下载一个带有PDF的zip文件和示例Server web应用程序configuration文件。 他们的邮政编码还包括使用Server 4.1进行此操作的历史说明。