我可以将Go应用程序与PHP应用程序一起部署的选项有哪些?

huangapple go评论85阅读模式
英文:

What are my options to deploy Go applications alongside PHP applications?

问题

我基本上想要实现的是让我的主要网站运行一个用Go编写的CMS。这将位于www.example.com。

我还有一些用PHP编写的应用程序,位于目录中,例如www.example.com/clients/。

我如何在使用Apache/PHP提供example.com/clients的同时,使用Go内置的Web服务器提供example.com?

英文:

What I'm basically trying to accomplish is having my main website running a CMS written in Go. This will be located at www.example.com.

I also have applications written in PHP located in directories, such as www.example.com/clients/

How can I serve example.com/clients using Apache/PHP while serving example.com using Go built-in web server?

答案1

得分: 4

Andrew Gerrand在他的博客文章中对此进行了很好的解释,针对nginx的原理与Apache相同。

您想将Apache设置为Go应用程序的反向代理,用于处理传入的请求。
对于Apache,您需要查看mod_proxy模块。

英文:

Andrew Gerrand has a good blog post about this for nginx but the principle is the same for Apache.

You want to set up Apache as a reverse proxy for requests coming in for the Go application.
For Apache you want to look at mod_proxy

答案2

得分: 4

通过在Apache2中使用mod_proxy,您可以将不同的路径代理到本地主机或服务器可访问的任何其他位置,包括本地网络(如果您的服务器可以访问它)。

为此,您可以使用ProxyPassApache2文档中的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来实现。我在服务器上的做法是将以下内容放入全局配置中(您应该自行验证其安全性):

# 禁用转发代理
ProxyRequests Off
英文:

Via mod_proxy in Apache2, you can proxy different paths into different destinations at localhost or anywhere else accessible by your server, including within your local network (if your server can access it).

For this you would use ProxyPass (Apache2 Docs for ProxyPass, which is very useful reading) like the example below:

&lt;VirtualHost *:80&gt;
  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/
&lt;/VirtualHost&gt;

You'll want to be sure that you set your proxy security such that external users can't use your reverse proxy as a forward proxy, too. You can do that via ProxyRequests as described in the official Apache2 docs. The way I did this on a server is to put this in your server-wide config (you should verify on your own that this is secure enough):

# disables forward proxy
ProxyRequests Off

huangapple
  • 本文由 发表于 2012年5月18日 05:11:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/10643599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定