mod_proxy - Apache HTTP Server Version 2.4
Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.4 Apache > HTTP Server > Documentation > Version 2.4 > Modules Apache Module mod_proxy Available Languages: en | fr | ja Description: Multi-protocol proxy/gateway server Status: Extension Module Identifier: proxy_module Source File: mod_proxy.c Summary Warning Do not enable proxying with ProxyRequests until you have secured your server .
Open proxy servers are dangerous both to your network and to the Internet at large. mod_proxy 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. A set of modules must be loaded into the server to provide the necessary features.
These modules can be included statically at build time or dynamically via the LoadModule directive). The set must include: mod_proxy , which provides basic proxy capabilities mod_proxy_balancer and one or more balancer modules if load balancing is required. (See mod_proxy_balancer for more information.) one or more proxy scheme, or protocol, modules: Protocol Module AJP13 (Apache JServe Protocol version 1.3) mod_proxy_ajp CONNECT (for SSL) mod_proxy_connect FastCGI mod_proxy_fcgi ftp mod_proxy_ftp HTTP/0.9, HTTP/1.0, and HTTP/1.1 mod_proxy_http HTTP/2.0 mod_proxy_http2 SCGI mod_proxy_scgi UWSGI mod_proxy_uwsgi WS and WSS (Web-sockets) mod_proxy_wstunnel In addition, extended features are provided by other modules.
Caching is provided by mod_cache and related modules. The ability to contact remote servers using the SSL/TLS protocol is provided by the SSLProxy* directives of mod_ssl . These additional modules will need to be loaded and configured to take advantage of these features. Topics Forward Proxies and Reverse Proxies/Gateways Basic Examples Access via Handler Workers Controlling Access to Your Proxy Slow Startup Intranet Proxy Protocol Adjustments Request Bodies Reverse Proxy Request Headers Directives BalancerGrowth BalancerInherit BalancerMember BalancerPersist NoProxy <Proxy> Proxy100Continue ProxyAddHeaders ProxyBadHeader ProxyBlock ProxyDomain ProxyErrorOverride ProxyIOBufferSize <ProxyMatch> ProxyMaxForwards ProxyPass ProxyPassInherit ProxyPassInterpolateEnv ProxyPassMatch ProxyPassReverse ProxyPassReverseCookieDomain ProxyPassReverseCookiePath ProxyPreserveHost ProxyReceiveBufferSize ProxyRemote ProxyRemoteMatch ProxyRequests ProxySet ProxySourceAddress ProxyStatus ProxyTimeout ProxyVia Bugfix checklist httpd changelog Known issues Report a bug See also mod_cache mod_proxy_ajp mod_proxy_balancer mod_proxy_connect mod_proxy_fcgi mod_proxy_ftp mod_proxy_hcheck mod_proxy_http mod_proxy_scgi mod_proxy_wstunnel mod_ssl Forward Proxies and Reverse Proxies/Gateways ¶ Apache HTTP Server can be configured in both a forward and reverse proxy (also known as gateway ) mode.
An ordinary forward proxy is an intermediate server that sits between the client and the origin server . In order to get content from the origin server, the client sends a request to the proxy naming the origin server as the target. The proxy then requests the content from the origin server and returns it to the client. The client must be specially configured to use the forward proxy to access other sites. A typical usage of a forward proxy is to provide Internet access to internal clients that are otherwise restricted by a firewall.
The forward proxy can also use caching (as provided by mod_cache ) to reduce network usage. The forward proxy is activated using the ProxyRequests directive. Because forward proxies allow clients to access arbitrary sites through your server and to hide their true origin, it is essential that you secure your server so that only authorized clients can access the proxy before activating a forward proxy. A reverse proxy (or gateway ), by contrast, appears to the client just like an ordinary web server.
No special configuration on the client is necessary. The client makes ordinary requests for content in the namespace of the reverse proxy. The reverse proxy then decides where to send those requests and returns the content as if it were itself the origin. A typical usage of a reverse proxy is to provide Internet users access to a server that is behind a firewall. Reverse proxies can also be used to balance load among several back-end servers or to provide caching for a slower back-end server.
In addition, reverse proxies can be used simply to bring several servers into the same URL space. A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive. It is not necessary to turn ProxyRequests on in order to configure a reverse proxy. Basic Examples ¶ The examples below are only a very basic idea to help you get started. Please read the documentation on the individual directives.
In addition, if you wish to have caching enabled, consult the documentation from mod_cache . Reverse Proxy ProxyPass "/foo" "http://foo.example.com/bar" ProxyPassReverse "/foo" "http://foo.example.com/bar" Forward Proxy ProxyRequests On ProxyVia On <Proxy "*"> Require host internal.example.com </Proxy> Websocket Upgrade (2.4.47 and later) ProxyPass "/some/ws/capable/path/" "http://example.com/some/ws/capable/path/" upgrade=websocket Access via Handler ¶ You can also force a request to be handled as a reverse-proxy request, by creating a suitable Handler pass-through.
The example configuration below will pass all requests for PHP scripts to the specified FastCGI server using reverse proxy: Reverse Proxy PHP scripts <FilesMatch "\.php$"> # Unix sockets require 2.4.7 or later SetHandler "proxy:unix:/path/to/app.sock|fcgi://localhost" </FilesMatch> This feature is available in Apache HTTP Server 2.4.10 and later. Workers ¶ The proxy manages the configuration of origin servers and their communication parameters in objects called workers .
There are two built-in workers: the default forward proxy worker and the default reverse proxy worker. Additional workers can be configured explicitly. The two default workers have a fixed configuration and will be used if no other worker matches the request. They do not use HTTP Keep-Alive or connection reuse. The TCP connections to the origin server will instead be opened and closed for each request. Explicitly configured workers are identified by their URL.
They are usually created and configured using ProxyPass or ProxyPassMatch when used for a reverse proxy: ProxyPass "/example" "http://backend.example.com" connectiontimeout=5 timeout=30 This will create a worker associated with the origin server URL http://backend.example.com that will use the given timeout values. When used in a forward proxy, workers are usually defined via the ProxySet directive: ProxySet "http://backend.example.com" connectiontimeout=5 timeout=30 or alternatively using Proxy and ProxySet : <Proxy "http://backend.example.com"> ProxySet connectiontimeout=5 timeout=30 </Proxy> Using explicitly configured workers in the forward mode is not very common, because forward proxies usually communicate with many different origin servers.
Creating explicit workers for some of the origin servers can still be useful if they are used very often. Explicitly configured workers have no concept of forward or reverse proxying by themselves. They encapsulate a common concept of communication with origin servers. A worker created by ProxyPass for use in a reverse proxy will also be used for forward proxy requests whenever the URL to the origin server matches the worker URL, and vice versa.
The URL identifying a direct worker is the URL of its origin server including any path components given: ProxyPass "/examples" "http://backend.example.com/examples" ProxyPass "/docs" "http://backend.example.com/docs" This example defines two different workers, each using a separate connection pool and configuratio
The rest of this page is on the live site.