如何配置 Apache 作为 j2ee 服务器的代理(负载均衡器)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/198564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:52:16  来源:igfitidea点击:

How to configure Apache to work as proxy (load balancer) for j2ee server?

apachejakarta-eemod-proxy

提问by Vik Gamov

I have apache web server installed as frontend and I have j2ee SAP Netweaver Application Server installed in Intranet server. How can I configure apache to forward requests and response to/from j2ee app server. for example, external apache server's ip is 9.20.1.1:80. internal sap server's address is 192.168.0.1/sap/bc/gui/sap/its/webgui?sap_client=200 I want access to my sap app server for example 9.20.1.1/sapserver/sap/bc/gui/sap/its/webgui?sap_client=200

我将 apache Web 服务器安装为前端,并且在 Intranet 服务器中安装了 j2ee SAP Netweaver Application Server。我如何配置 apache 以向/从 j2ee 应用服务器转发请求和响应。例如外部apache服务器的ip是9.20.1.1:80。内部 sap 服务器的地址是 192.168.0.1/sap/bc/gui/sap/its/webgui?sap_client=200 我想访问我的 sap 应用服务器,例如 9.20.1.1/sapserver/sap/bc/gui/sap/its/ webgui?sap_client=200

采纳答案by MattMcKnight

You mentioned load balancing- so presumably you want to be able to add more Application Servers that are served through a single address. I hope they are stateless or storing session information in a database. You can use Apache to serve as a reverse proxy load balancer with mod_proxy_balancer. Docs are here.

您提到了负载平衡——因此大概您希望能够添加更多通过单个地址提供服务的应用服务器。我希望它们是无状态的或将会话信息存储在数据库中。您可以使用 Apache 作为反向代理负载均衡器mod_proxy_balancer。文档在这里

Here's an example of what to add to your httpd.conf from this link.

这是从这个链接添加到 httpd.conf 的示例。

 <Proxy balancer://myclustername>
  # cluster member 1
  BalancerMember http://192.168.0.1:3000 
  BalancerMember http://192.168.0.1:3001

  # cluster member 2, the fastest machine so double the load
  BalancerMember http://192.168.0.11:3000 loadfactor=2
  BalancerMember http://192.168.0.11:3001 loadfactor=2

  # cluster member 3
  BalancerMember http://192.168.0.12:3000
  BalancerMember http://192.168.0.12:3001

  # cluster member 4
  BalancerMember http://192.168.0.13:3000
  BalancerMember http://192.168.0.13:3001
</Proxy>

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName www.meinprof.de
  ServerAlias meinprof.de
  ProxyPass / balancer://meinprofcluster/
  ProxyPassReverse / balancer://meinprofcluster/
  ErrorLog /var/log/www/www.meinprof.de/apache_error_log
  CustomLog /var/log/www/www.meinprof.de/apache_access_log combined
</VirtualHost>

回答by jrwren

This is often mistakenly referred to as a reverse proxy. If you use a search engine to find "reverse proxy apache" you will get many good results.

这通常被错误地称为反向代理。如果您使用搜索引擎查找“反向代理apache”,您会得到很多不错的结果。

The quick answer is to add something like this to your apache.conf

快速回答是将这样的内容添加到您的 apache.conf

ProxyPass /sap/ 192.168.0.1/sap/

< Location /sap/ >

    ProxyPassReverse /sap/ 

< /Location >

ProxyPass /sap/ 192.168.0.1/sap/

<位置/sap/>

    ProxyPassReverse /sap/ 

</位置>

See also the modrewrite rools and the [P] option.

另请参阅 modrewrite 角色和 [P] 选项。

回答by Mark Roddy

Assuming you have mod_proxy enabled, add to you're sites-available:

假设您启用了 mod_proxy,请添加到您可用的站点:

   ProxyRequests Off
   <Location "/sapserver">
        ProxyPass http://192.168.0.1
        ProxyPassReverse http://192.168.0.1
   </Location>

Be careful though as this does expose your internal site to the entire internet.

不过要小心,因为这确实会将您的内部网站暴露给整个互联网。