Академический Документы
Профессиональный Документы
Культура Документы
Contents
Feb 14, 2014
14 7
Introduction
Apache is a tried and tested HTTP server which comes with access to a very wide range of
powerful extensions. Although it might not seem like the go-to choice in terms of running a
reverse-proxy, system administrators who already depend on Apache for the available rich
feature-set can also use it as a gateway to their application servers. In most cases, this will
translate to removing an additional layer from their server set up or the need to use yet
another tool just to redirect connections.
In this DigitalOcean article, we are going to see set up Apache on Ubuntu 13 and use it as a
reverse-proxy to welcome incoming connections and redirect them to application server(s)
running on the same network. For this purpose, we are going to use and work with the
mod_proxy extension and several other related Apache modules.
Glossary
1. Apache
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 1/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Apache
Apache HTTP server does not require an introduction, since it is probably the most famous
and popular web-server that exists. It is possible to run Apache very easily on many different
platforms and set ups. The application comes with a lot of third party modules to handle
different kind of tasks (modrewrite for rule-based URL rewriting) and one of them, albeit
nowadays relatively neglected, is *modproxy*: The Apache Module to implement a proxy (or
gateway) for servers running on the back-end.
Tip: According to some articles, Apache's name comes from server's "patchy"
nature - i.e. it being a collection of application patches (or modules).
Note: To learn more about Apache, you can check out the Wikipedia entry on the subject -
Apache HTTP Server.
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 2/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
mod_proxy: The main proxy module for Apache that manages connections and
redirects them.
modproxyhttp: This module implements the proxy features for HTTP and HTTPS
protocols.
modproxyftp: This module does the same but for FTP protocol.
Note: To learn more about Apache and mod_proxy, you can check out the official Apache
documentation on the subject here.
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 3/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Update the software sources list and upgrade the dated applications:
aptitudeupdate
aptitudeyupgrade
aptitudeinstallybuildessential
aptitudeinstallylibapache2modproxyhtmllibxml2dev
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 4/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
First, let's verify that all modules are correctly installed and ready to be activated.
a2enmod
#Youwillbepresentedwithanoutputsimilarto:
#Yourchoicesare:access_compatactionsaliasallowmethodsasisauth_basicauth_digesta
#Whichmodule(s)doyouwanttoenable(wildcardsok)?
Once you are prompted with the choice of modules you desire, you can pass the below line
listing the module names:
proxyproxy_ajpproxy_httprewritedeflateheadersproxy_balancerproxy_connectproxy_html
Or alternatively, you can run the following commands to enable the modules one by one:
a2enmodproxy
a2enmodproxy_http
a2enmodproxy_ajp
a2enmodrewrite
a2enmoddeflate
a2enmodheaders
a2enmodproxy_balancer
a2enmodproxy_connect
a2enmodproxy_html
Note: Some modules are likely to be enabled by default. Trying to enable them twice will just
ensure that they are active.
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 5/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Run the following command to edit the default Apache virtual host using the nano text editor:
nano/etc/apache2/sitesenabled/000default.conf
Here, we will be defining a proxy virtual host using mod_virtualhost and mod_proxy
together.
<VirtualHost*:*>
ProxyPreserveHostOn
#Serverstoproxytheconnection,or;
#Listofapplicationservers:
#Usage:
#ProxyPass/http://[IPAddr.]:[port]/
#ProxyPassReverse/http://[IPAddr.]:[port]/
#Example:
ProxyPass/http://0.0.0.0:8080/
ProxyPassReverse/http://0.0.0.0:8080/
ServerNamelocalhost
</VirtualHost>
Note: To learn more about virtual host configurations, you can check out the detailed Apache
manual on the subject by clicking here.
Enabling Load-Balancing
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 6/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
If you have multiple back-end servers, a good way to distribute the connection when
proxying them is to use Apache's load balancing features.
Start editing the virtual-host settings like the previous step, but this time using the below
configuration example:
<Proxybalancer://mycluster>
#Definebackendservers:
#Server1
BalancerMemberhttp://0.0.0.0:8080/
#Server2
BalancerMemberhttp://0.0.0.0:8081/
</Proxy>
<VirtualHost*:*>
#ApplyVHsettingsasdesired
#However,configureProxyPassargumentto
#use"mycluster"tobalancetheload
ProxyPass/balancer://mycluster
</VirtualHost>
Repeat the steps from the previous steps but using these configuration options:
Listen443
NameVirtualHost*:443
<VirtualHost*:443>
SSLEngineOn
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 7/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
#SetthepathtoSSLcertificate
#Usage:SSLCertificateFile/path/to/cert.pem
SSLCertificateFile/etc/apache2/ssl/file.pem
#Serverstoproxytheconnection,or;
#Listofapplicationservers:
#Usage:
#ProxyPass/http://[IPAddr.]:[port]/
#ProxyPassReverse/http://[IPAddr.]:[port]/
#Example:
ProxyPass/http://0.0.0.0:8080/
ProxyPassReverse/http://0.0.0.0:8080/
#Or,balancetheload:
#ProxyPass/balancer://balancer_cluster_name
</VirtualHost>
Restarting Apache
Once you are happy with your configuration, you will need to restart the cloud server for the
changes to go into effect.
serviceapache2restart
You can now visit your VPS and Apache shall reverse-proxy connections to your back-end
application servers.
Heart 14 Subscribe
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 8/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
DEPLOY SERVER
Related Tutorials
How To Migrate your Apache Configuration from 2.2 to 2.4 Syntax.
How To Get Started With mod_pagespeed with Apache on a CentOS and Fedora Cloud
Server
7 Comments
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 9/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Leave a comment...
Log In to Comment
here no php
Reply
<IfModulemod_deflate.c>
#Insertfilter
SetOutputFilterDEFLATE
AddOutputFilterByTypeDEFLATEapplication/atom+xml\
application/javascript\
application/json\
application/rss+xml\
application/vnd.msfontobject\
application/xfontttf\
application/xhtml+xml\
application/xml\
font/opentype\
image/svg+xml\
image/xicon\
text/css\
text/html\
text/plain\
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 10/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
text/xcomponent\
text/xml
#Netscape4.xhassomeproblems...
BrowserMatch^Mozilla/4gziponlytext/html
#Netscape4.064.08havesomemoreproblems
BrowserMatch^Mozilla/4\.0[678]nogzip
#MSIEmasqueradesasNetscape,butitisfine
#BrowserMatch\bMSIE!nogzip!gziponlytext/html
#NOTE:Duetoabuginmod_setenvifuptoApache2.0.48
#theaboveregexwon'twork.Youcanusethefollowing
#workaroundtogetthedesiredeffect:
BrowserMatch\bMSI[E]!nogzip!gziponlytext/html
#Don'tcompressimages
SetEnvIfNoCaseRequest_URI\
\.(?:gif|jpe?g|png)$nogzipdontvary
#Makesureproxiesdon'tdeliverthewrongcontent
HeaderappendVaryUserAgentenv=!dontvary
#excludethefollowingfiletypes
SetEnvIfNoCaseRequest_URI\.(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|g
#setcompressionlevel
DeflateCompressionLevel9
</IfModule>
...
</VirtualHost>
I hope it can be useful.
Reply
Configure your:
ProxyPass and ProxyPassReverse.
I hope you can help with this because I am a little bit confused.
I'm an apache 2.2 httpd and want to communicate to a secured server which is also
HTTPS SSL by using ProxyPass and ProxyPassReverse.
Sample architecture:
Outside world ==> https ssl Apache 2.2 httpd (localhost) ==> Secured server Https ssl
(domain.com)
I am the middle man here.
What exactly do I need from them (domain.com) in order for me to configure Apache
2.2 httpd-ssl.conf properly?
Do I only need their public key? I don't think I also need their certificate, otherwise I can
generate their private key. I don't think that's handy...and insecured.
This is my current configuration when the outside world visit the middle man apache
server. Can you take a look and check what I am missing to get it working theoretically?
=======
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 12/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Listen 8443
<VirtualHost *:8443>
ServerName localhost.localdomain
SSLEngine on
SSLCertificateFile /etc/httpd/conf.d/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/conf.d/ssl/server_priv.pem
ProxyRequestsoff
SSLProxyEngineon
Logleveldebug
ErrorLog/home/df/Desktop/errorLog_443.txt
TransferLog/home/df/Desktop/transferLog_443.txt
<Location/gd_endpoint/>
ProxyPasshttps://domain.com:45093/abc/1.1.0
ProxyPassReversehttps://domain.com:45093/abc/1.1.0
Orderdeny,allow
Denyfromall
Allowfromall
</Location>
Reply
Leave a comment...
Log In to Comment
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 13/14
6/10/2015 HowToUseApacheHTTPServerAsReverseProxyUsingmod_proxyExtension|DigitalOcean
Copyright 2015 DigitalOcean Inc.
Terms, Privacy, & Copyright Security Report a Bug Get Paid to Write
https://www.digitalocean.com/community/tutorials/howtouseapachehttpserverasreverseproxyusingmod_proxyextension 14/14