+-

我基本上要完成的是让我的主网站运行用Go编写的CMS.这将位于www.example.com.
我还有用PHP编写的应用程序,位于目录中,例如www.example.com/clients/
如何在使用Go内置Web服务器提供example.com时使用Apache / PHP提供example.com/clients?
最佳答案
通过Apache2中的mod_proxy,您可以将不同的路径代理到localhost或服务器可访问的任何其他目标,包括在本地网络中(如果您的服务器可以访问它).
为此,您将使用ProxyPass(Apache2 Docs for ProxyPass,这是非常有用的阅读),如下例所示:
<VirtualHost *:80>
ServerName some.example.host.xyz
DocumentRoot /var/www/your-document-root
Alias /clients/ /var/www/clients/
ProxyPass /clients/ !
ScriptAlias /something-using-cgi/ /var/www/cgi-stuff/
ProxyPass /something-using-cgi/ !
ProxyPreserveHost On
ProxyPass / http://localhost:9876/
ProxyPassReverse / http://localhost:9876/
ProxyPass /elsewhere/ http://elsewhere.example.host.xyz:1234/
ProxyPassReverse /elsewhere/ http://elsewhere.example.host.xyz:1234/
</VirtualHost>
您需要确保设置代理安全性,以便外部用户也不能将反向代理用作转发代理.您可以通过官方Apache2文档中描述的ProxyRequests执行此操作.我在服务器上执行此操作的方法是将其放在服务器范围的配置中(您应该自己验证这是否足够安全):
# disables forward proxy
ProxyRequests Off
点击查看更多相关文章
转载注明原文:apache – 我可以选择将Go应用程序与PHP应用程序一起部署吗? - 乐贴网