Modproxy and related modules implement a proxy/gateway for Apache HTTP Server, supporting a number of popular protocols as well as several different load balancing algorithms. Third-party modules can add support for additional protocols and load balancing algorithms. For more details about modproxy from the perspective of the JBoss Enterprise Application Platform, refer to Section 13.5.1, “About the Apache modproxy HTTP Connector” and Section 13.1.3, “Overview of HTTP Connectors”. One of the popular methods is by setting up the connection with modproxy or modrewrite which are quite easy in terms of configurations. These basic configurations help Apache start passing on request to the back-end Tomcat server and conveys the responses back to the client.
- Apache + Tomcat: Using modproxy instead of AJP. Ask Question Asked 11 years, 10 months ago. Active 4 years, 7 months ago. Viewed 57k times 21. Is there any way I connect Apache to Tomcat using an HTTP proxy such that Tomcat gets the correct incoming host name rather than localhost? I'm using this directive in apache.
- If you decide that you must run Tomcat behind Apache httpd, we suggest using only the built-in modproxy module for proxying the requests to Tomcat. To use modproxy, search for the following lines.
Published on November 1, 2018by Daniel Lanza
Mod_proxy Tomcat Example
This tutorial will explain how to load balancing two Tomcat instances with Apache HTTPD server with mod_proxy and mod_proxy_balancer modules.
![Mod_proxy Tomcat Mod_proxy Tomcat](/uploads/1/3/7/8/137884988/515089794.png)
The environment will be simulated with three virtual machines and VirtualBox:
# | Server FQDN | IP | |
---|---|---|---|
1 | apache-server.dalanzg.com | 192.168.56.101 | Apache HTTPD - Port 80 |
2 | tomcat-server1.dalanzg.com | 192.168.56.102 | Apache Tomcat - Port 8080 |
3 | tomcat-server2.dalanzg.com | 192.168.56.103 | Apache Tomcat - Port 8080 |
Check the following post to configure openSUSE with Internet and statick IP address by using YaST on VirtualBox
Steps
Install Apache HTTPD
Install Apache HTTP in server #1
Check Apache HTTPD works in server #1 from your host machine.
Install Apache Tomcat
Steps for servers #2 and #3:
- Download apache-tomcat-8.5.34.tar.gz
- Deploy Apache Tomcat and change permissions
- Start service
- Create a static html file
And create a static html file.
Check you can reach the index page from servers #2 and #3:
- http://192.168.56.102:8080/dalanzg
- http://192.168.56.103:8080/dalanzg
Load apache modules
First, load the following modules by editing loadmodule.conf file:
- mod_proxy -> Redirect connections. It allows Apache to act as a gateway to the underlying application servers.
- mod_proxy_http -> Add support for proxying HTTP connections
- mod_proxy_balancer -> Add load balancing features for multiple backend servers
- mod_lbmethod_byrequests -> Parameter to specify balance by requests
- mod_slotmem_shm -> Requirement for mod_proxy_balancer
Add the modules at the end:
Restart and check if Apache modules are loaded.
Example 1 - Reverse Proxying a Single Backend Server
All the Apache requests http://192.168.56.101/dalanzg will be redirected to server #2 (http://192.168.56.102:8080/dalanzg)
First, enable the modules mod_proxy and mod_proxy_http with a2enmod, and restart apache.
Create the a configuration file in /etc/apache2/vhosts.d
- ProxyPreserveHost -> Makes Apache pass the original Host header to the backend server.
- ProxyPass -> The rule to redirect. If we only write /, all the request from Apache will be redirected
- ProxyPassReverse -> It tells Apache to modify the response headers from backend server. This makes sure that if the backend server returns a location redirect header, the client’s browser will be redirected to the proxy address and not the backend server address, which would not work as intended.
Let’s check the following URL -> http://192.168.56.101/dalanzg
Example 2 - Load Balancing Across Multiple Backend Servers
All the Apache request will be balanced from http://192.168.56.101/dalanzg to:
- http://192.168.56.102:8080/dalanzg
- http://192.168.56.103:8080/dalanzg
Rename the Example 1 configuration file to singlebackend.conf.bak to disable the rule and restart apache.
Activate the 5 modules and restart apache.
Create a new conf file.
- ProxyRequests off -> Turn off the standard proxy feature of mod_proxy.so
- BalancerMember -> The Worker URLs to balance
- ProxySet lbmethod=byrequests -> Balance by requests
- SetHandler balancer-manager -> Enable the balancer-manager page
And check how the page http://192.168.56.101/dalanzg is balanced from server #2 and #3.
Check the balancer-manager status -> http://192.168.56.101/balancer-manager
If Tomcat 2 (server #3) were down, the URL http://192.168.56.101/dalanzg would be still working, since the requests would go always to Tomcat 1 (server #2). Let’s try it.
Shutdown Tomcat 2 in server #3.
![Mod_proxy tomcat load balancing Mod_proxy tomcat load balancing](/uploads/1/3/7/8/137884988/881307893.png)
Go several times to the URL http://192.168.56.101/dalanzg, and you will only see Tomcat 1 page.
Errors to balance Worker URL 2 will be gotten.
Please enable JavaScript to view the comments powered by Disqus.comments powered by DisqusRead next
Previous Post:openSUSE with Internet and static IP address by using YaST on VirtualBox
Mod_proxy Tomcat
Next Post:Tomcat load balancing with HAProxy in openSUSE
See also
Mod_proxy Apache Tomcat
This tutorial will explain how to install Apache HTTPD in openSUSE 15.The original documentation is found in The Apache HTTP Server Project. And the official documentation for openSUSE is in The Apache HTTP Server.Requirements You will need the following:openSUSE Leap 15 Steps Set hostname and domain Install Apache HTTPD Start and stop Apache Start Apache automatically at boot time Set hostname and domain Files /etc/hostname and /etc/hosts will be modified to resolve the following:
Read moreAn openSUSE virtual machine will be configured to have a static IP address and Internet connection on VirtualBox.This scenario is really useful if you want to install a specific application in guest and you need to communicate from your host.Therefore, the virtual machine will have two network adapters:NAT -> Internet connection Host-only-adapter -> Static IP address (192.168.56.200) and FQDN server1.dalanzg.com Steps Settings for VirtualBox Virtual machine network settings Settings for network devices Settings for VirtualBox First, create a Host Network Manager in VirtualBox.
Read moreThis tutorial will explain how to install Oracle Database 12c R2 in openSUSE Leap 42.3.Requirements You will need the following:openSUSE Leap 42.3 -> Install openSUSE virtual machine with VirtualBox Oracle 12c R2 database installation file -> linuxx64_12201_database.zip Steps Install libraries Set hostname and domain Create groups and users Grant oracle user access to X server Configuring Kernel Parameters and Resource Limits Create directory for Oracle Database Install Oracle Database Configuration of Oracle Listener Configuration of Oracle Database Create user for database Create table for database Connect to Oracle database with SQL Developer Start database when server is restarted Install libraries According to Supported SUSE Linux Enterprise Server 12 in Oracle documentation, install the following libraries by using YaST or zypper command:
Read more