• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Ubuntu 18.04 Apache Reverse Proxy, Loadbalancer Configuration Step by Step

By Abhishek Ghosh September 8, 2018 9:23 am Updated on September 8, 2018

Ubuntu 18.04 Apache Reverse Proxy, Loadbalancer Configuration Step by Step

Advertisement

In our older guides we have shown to configure Nginx as IPv6 reverse proxy. Apache Webserver also can work as loadbalancer. Here is Ubuntu 18.04 Apache Reverse Proxy, Loadbalancer Configuration Step by Step Guide. For HSTS site, the configuration and steps are quite complex and probably Nginx is lighter and easy to consider. It is PHP-FPM which throws odd errors with Nginx, but Nginx is highly stable as reverse proxy and loadbalancer. Using Apache as reverse proxy and/or loadbalancer demands working knowledge on Apache webserver as well as knowledge on basic theoretical knowledge.

 

Apache Reverse Proxy, Loadbalancer Configuration Step by Step

 

We will take it granted that the backend servers you’ll loadbalance are HTTPS. Unlike Nginx, just to reverse proxy one backend server; you have to configure like complete loadbalancer else Apache on minimum error will serve local directories! Nginx basically become loadbalancer when we simply listen to IP or host outside local network. Apache is complete package, upon facing error it thinks that we are doing the wrong and serve local files (which actually for good intention). Apache however is quite powerful as loadbalancer. Most importantly, Apache is completely Libre Software and unlike Nginx has no paid part of more options! It is time taking to learn as first timer but worth on long run.

You need to add the IP (IPv4 or IPv6) of the server to DNS record of domain before the final step. In our earlier guide, we have described specific configuration of Apache IPv6 as webserver – it is suggested to finally configure server in that way.

Advertisement

---

SSH as root user. Update and upgrade :

Vim
1
2
apt update -y
apt upgrade -y

We will install Apache2 from Ondřej Surý’s PPA :

Vim
1
2
3
4
5
6
7
8
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/apache2
# hit enter/return key to accept
apt update -y
apt upgrade -y
sudo apt install apache2
## apache2-bin has libapache2-mod-proxy-html, which is a dependency
sudo apt install apache2-bin libxml2-dev

You’ll get list of modules as output which will be automatically activated, like :

Vim
1
2
3
4
5
6
7
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
...

Ubuntu 18-04 Apache Reverse Proxy Loadbalancer Configuration Step by Step

We need to activate more modules and restart Apache :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
sudo a2enmod proxy_ajp
sudo a2enmod rewrite
sudo a2enmod deflate
sudo a2enmod headers
sudo a2enmod proxy_connect
sudo a2enmod proxy_html
sudo a2enmod ssl
sudo a2enmod http2

Then restart Apache2 :

Vim
1
service apache2 restart

Now copy the SSL certificates from main server, in our guides like to renewal GeoTrust or RapidSSL/Comodo cert, they are on the below path of original server :

Vim
1
2
3
/usr/local/ssl/crt/public.crt
/usr/local/ssl/private/private.key
/usr/local/ssl/crt/intermediate.crt

You can SSH from other terminal window, cat each file, copy their content and paste on this server. Alternatively you can copy via FTP. Now go to /etc/apache2/sites-available and perform ls -al :

Vim
1
2
cd /etc/apache2/sites-available
ls

There will be two files – 000-default.conf and default-ssl.conf. Disable those configurations and restart Apache :

Vim
1
2
3
sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
service apache2 restart

Create two new configurations with memorable names, activate :

Vim
1
2
3
4
cd /etc/apache2/sites-available/
rm 000-default.conf default-ssl.conf
touch loadbalancer.conf loadbalancer-ssl.conf
ls

Basic configuration for proxy for port 80 is like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  ProxyPreserveHost On
  # Servers to proxy the connection, or
  # List of application servers Usage
  ProxyPass / http://server-ip-address:8080/
  ProxyPassReverse / http://server-ip-address:8080/
  ServerName localhost
</VirtualHost>

Basic configuration for proxy for port 443 is like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine On
        # Set the path to SSL certificate
        SSLCertificateFile /etc/ssl/private/public.crt
        SSLCertificateKeyFile /etc/ssl/private/private.key
        SSLCertificateChainFile /etc/ssl/private/intermediate.crt
        ProxyPreserveHost On
        ProxyPass /var/www/ http://server-ip-address:8080/
        ProxyPassReverse /var/www/ http://server-ip-address:8080/
        ServerName localhost
</VirtualHost>

Save them for now, run configuration test :

Vim
1
sudo apache2ctl configtest

Enable new virtual host file:

Vim
1
sudo a2ensite loadbalancer.conf loadbalancer-ssl.conf

Then restart Apache :

Vim
1
service apache2 restart

For loadbalancing, you need Proxy Balancer on the top of the above basic configuration, and Proxy Pass that cluster :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<Proxy balancer://cluster1>
    # Define back-end servers:
    ## Server 1
    BalancerMember http://0.0.0.0:8080/
    ## Server 2
    # BalancerMember http://0.0.0.0:8081/
</Proxy>
 
<VirtualHost *:443>
        SSLEngine On
        # Set the path to SSL certificate
        SSLCertificateFile /etc/ssl/private/public.crt
        SSLCertificateKeyFile /etc/ssl/private/private.key
        SSLCertificateChainFile /etc/ssl/private/intermediate.crt
 
    ## ProxyPass / http://0.0.0.0:8080/
    ## ProxyPassReverse / http://0.0.0.0:8080/
    # Or balance the load:
    ProxyPass / balancer://cluster1
 
</VirtualHost>

You can find official documents on Apache’s site :

Vim
1
https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

We have demonstrated the steps of basic setup. Apache is highly configurable. There are advanced guides on web to test other settings, such as :

Vim
1
https://www.netnea.com/cms/apache-tutorial-9_setting-up-a-reverse-proxy/

Tagged With install mod_proxy ubuntu 18 04 , ubuntu 18 04 install mod_proxy , ubuntu 18 04 apache2 proxy module , ubuntu 18 04 apache reverse proxy installation , reverse proxy ubuntu 18 apache , reverse proxy ubuntu 18 04 , Reverse Proxy for Apache on One Ubuntu 18 04 , load balancer creating steps in ubuntu , install apache reverse proxy ubuntu 18 04 , ubuntu 18 04apache mod_proxy
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Ubuntu 18.04 Apache Reverse Proxy, Loadbalancer Configuration Step by Step

  • How to Configure Apache as Reverse Proxy (Ubuntu, Cloud Server)

    Here is How to Configure Apache as Reverse Proxy on Single Cloud Server Instance Running Ubuntu 16.04 For IPv4. We Have Not Tested For IPv6.

  • How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS

    Here is Detailed Guide on How To Install Apache2 on Ubuntu 18.04 With Let’s Encrypt, HTTP/2, HSTS With Commands and Configurations For Most Secured Setup.

  • Install Elastic Stack on Ubuntu 16.04, CentOS 7 Single Cloud Server

    Here is How to Install Elastic Stack on Ubuntu 16.04, CentOS 7 on Single Cloud Server Instance For Server Log Analysis, Big Data Processing.

  • Proxy Server and Reverse Proxy

    Proxy Server and Reverse Proxy Sound Quite Closer to Common Man. Here we have discussed these Two Different Communication interfaces in a Network.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy