Skip to content
Follow
Ubuntu Linux

How to Setup Apache Reverse Proxy

Richard
Written by
Richard
Oct 11, 2021 Updated Jul 10, 2026 3 min read
Enable Automatic Suspension in Ubuntu Linux Easily
Enable Automatic Suspension in Ubuntu Linux Easily

You set up Apache as a reverse proxy by configuring modules like mod_proxy and mod_proxy_http to direct client requests to your backend servers.

A reverse proxy gateway intercepts client requests and forwards client requests to backend services. This gateway design boosts security, enhances performance using caching, and distributes traffic load effectively across at least 3 backend servers.

Apache modules `mod_proxy` and `mod_proxy_http` activate Apache as a reverse proxy server. This configuration is standard for Apache version 2.4 and newer. The reverse proxy handles application traffic for programs such as Node.js or Python.

This configuration proves invaluable when your backend applications don’t include built-in web server capabilities, allowing you to centralize and streamline request handling.

⚡ Quick Answer

Enable Apache modules like `mod_proxy` and `mod_proxy_http` using `a2enmod`. Then, configure a VirtualHost block with `ProxyPass` and `ProxyPassReverse` directives to specify the backend server address. This directs client requests to your specified application server.

How to use Apache as a reverse proxy server

Apache needs special tools called modules to work as a reverse proxy. You must turn on `mod_proxy` and `mod_proxy_http` modules. These modules help Apache handle website traffic by sending visitor requests to another server and getting answers back.

Here’s how to enable these Apache modules:

The `ProxyPass` directive in Apache web server configuration identifies the backend server that receives incoming website requests. This configuration line makes the Apache proxy server act as a middleman, forwarding traffic to the correct server. Apache version 2.4.54 commonly uses this directive.

💻Code
<VirtualHost *:*>
    ServerName example.com
    ProxyPreserveHost On

    # Servers to proxy the connection, or;

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

</VirtualHost>

This configuration tells Apache to send all requests for your example.com domain’s root directory (/) to the server at http://127.0.0.1:8080.

⚠️Warning
For example, if a client requests http://example.com/, Apache will forward the request to the backend server defined on the ProxyPass and ProxyPassReverse lines: http://127.0.0.1:8080.

Apache provides many advanced settings for proxy servers beyond this basic setup. This clear example illustrates how Apache proxy servers function.

Apache can also handle requests for non-HTTP servers, such as:

  • proxy_fcgi – reverse proxy to a FastCGI server.
  • proxy_uwsgi – reverse proxy to a uwsgi server.
  • proxy_scgi – reverse proxy to an SCGI server.
📝Good to Know
A common Apache reverse proxy to non-HTTP hosts is done using PHP-FPM. An example is how Apache serves PHP scripts.
🐘PHP
<VirtualHost *:*>
    ServerName example.com
    ProxyPreserveHost On

    # Servers to proxy the connection, or;

    <FilesMatch .php$>
        # 2.4.10+ can proxy to unix socket
         SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>

</VirtualHost>

You will need to enable a few modules for apache2 to work with PHP-FPM:

Apache reverse proxy configuration involves setting up special options to control how the Apache server deals with incoming requests and sends them to other servers. This Apache reverse proxy setup tells Apache exactly where to send traffic and how to keep important details, like the original website address, correct.

💻Code
<VirtualHost *:*>
    ServerName example.com

    UseCanonicalName on
    ProxyPreserveHost on
    CacheStaleOnError on
    RemoteIPHeader X-Forwarded-For
    ProxyRequests Off

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

</VirtualHost>

You can visit the site for more options to use in your environment.

That should do it!

Conclusion:

  • Setting up Apache as a reverse proxy allows you to efficiently manage client requests and backend servers.
  • Apache provides extensive modules that enhance its functionality for reverse proxy operations.
  • Simple configurations can effectively route requests to desired backend applications, such as Node.js, Python, and PHP-FPM.
  • Advanced configurations are available for handling various types of requests beyond HTTP.
  • Understanding the fundamental reverse proxy concepts can help optimize web application performance and reliability.
  • For further customization and options, refer to the official Apache documentation on reverse proxy settings.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Edit Hosts File with PowerToys on Windows 11
Windows How to Edit Hosts File with PowerToys on Windows 11
How to Turn "Week Numbers" On or Off for Calendar in Ubuntu Linux
Ubuntu Linux How to Turn "Week Numbers" On or Off for Calendar in Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *