Skip to content
Follow
Ubuntu Linux

How to Setup Apache Reverse Proxy

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

An Apache reverse proxy is a server setup that takes incoming web traffic and sends it to the right backend application. Running Apache version 2.4 or newer gives you built-in modules that handle this traffic routing directly.

Advertisement

This setup helps protect your web apps and spreads visitor traffic across multiple servers so your site stays fast. It works well for programs like Node.js or Python that lack their own built-in web servers.

⚡ 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.

Advertisement

How to use Apache as a reverse proxy server

Apache reverse proxy setup requires turning on the proxy and proxy_http modules in your server configuration files. These modules let Apache act as a gateway that passes incoming visitor requests to a back-end server and sends the response back to the user, hiding your internal network details.

Here is how to enable these Apache modules:

The ProxyPass directive in the Apache web server configuration identifies the backend server that will receive 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.

<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 the example.com domain’s root directory (/) to the server at http://127.0.0.1:8080.

Advertisement

For example, if a client requests http://example.com/, Apache forwards that request to the backend server defined on the ProxyPass and ProxyPassReverse lines: http://127.0.0.1:8080.

Apache offers advanced settings for proxy servers beyond this basic configuration. This example illustrates how Apache proxy servers function.

Apache also handles 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.

Apache often proxies requests to non-HTTP hosts using PHP-FPM. This method represents the standard way Apache serves PHP scripts.

Advertisement
<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>

Enabling a few modules allows apache2 to work with PHP-FPM:

Configuring an Apache reverse proxy involves setting up options that dictate how the server handles incoming requests and forwards them. This setup ensures Apache knows precisely where to send traffic and preserves critical details, such as the original website address.

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

Consult the site for more options to use in your environment.

Setting up Apache as a reverse proxy allows you to efficiently manage client requests and backend servers.

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.

Advertisement

📚 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 Setup a Proxy in Windows 11
Windows How to Setup a Proxy in 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
How to Install Magento with Apache and Cloudflare on Ubuntu Linux
CMS How to Install Magento with Apache and Cloudflare on 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 *