• 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

This Article Has Been Shared 784 Times!

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

  • Create Data Science Environment on Cloud Server With Docker

    Here Are the Steps, Commands to Create Data Science Environment on Cloud Server For Data Analysis Starting With a Blank Server With SSH.

  • How to Install and Set Up LXD on Ubuntu 16.04

    Here is How to Install and Set Up LXD on Ubuntu 16.04. LXD Works With a Directory Based Storage Backend. LXD is lxc with strong security.

  • How To Run Docker, Containers On IBM Bluemix

    On How To Run Docker, Containers On IBM Bluemix Guide We Have Provided Clear Instructions, Commands to Setup the Command Line Tools on Mac.

  • How to Install Chamilo on Ubuntu Server (Learning Management Software)

    Chamilo is a free software for e-learning. Chamilo runs on a LAMP server and easy to install. Here is How to Install Chamilo on Ubuntu Server.

  • Staging Environment vs Production Environment

    DEV, TEST, STAGING, PROD Are Common 4 Environments. What Are The Differences Between Staging Environment vs Production Environment?

Additionally, 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

  • What Online Casinos Have No Deposit Bonus in Australia March 30, 2023
  • Four Foolproof Tips To Never Run Out Of Blog Ideas For Your Website March 28, 2023
  • The Interactive Entertainment Serving as a Tech Proving Ground March 28, 2023
  • Is it Good to Run Apache Web server and MySQL Database on Separate Cloud Servers? March 27, 2023
  • Advantages of Cloud Server Over Dedicated Server for Hosting WordPress March 26, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Ubuntu 18.04 Apache Reverse Proxy, Loadbalancer Configuration Step by Step," in The Customize Windows, September 8, 2018, March 31, 2023, https://thecustomizewindows.com/2018/09/ubuntu-18-04-apache-reverse-proxy-loadbalancer-configuration-step-by-step/.

Source:The Customize Windows, JiMA.in

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT