Skip to content

Instantly share code, notes, and snippets.

@xcooper
Last active August 31, 2015 10:35
Show Gist options
  • Save xcooper/c4eadf8e6e33be7d4e5c to your computer and use it in GitHub Desktop.
Save xcooper/c4eadf8e6e33be7d4e5c to your computer and use it in GitHub Desktop.
Apache httpd reverse proxy
<IfModule proxy_module>
<IfModule proxy_http_module>
#LogLevel alert trace3
#################
# Reverse Proxy #
#################
ProxyRequests Off
ProxyTimeout 3600
# turn this on if there are https URL to handle with.
SSLProxyEngine On
# uncomment following settings if it's a self-signed certification on the server.
#SSLProxyVerify none
#SSLProxyCheckPeerCN off
#SSLProxyCheckPeerName off
# turn rewrite engine on if outside hostname not equals to the inside one.
# (browser -> w1.company.com -> reverse proxy -> w2.company.com -> server)
RewriteEngine On
##############################################
# reverse proxy for http / https dynamically #
##############################################
# TODO now we have problem while chinese chars in URL
#
# RewriteCond "%{HTTPS}" =off
# RewriteRule "." "-" [E=protocol:http]
# RewriteCond "%{HTTPS}" =on
# RewriteRule "." "-" [E=protocol:https]
#
# RewriteRule "^/(.*)" "%{ENV:protocol}://server.company.com/$1" [R,QSA]
###########################
# rewrite content in HTML #
###########################
# turn ProxyHTML off if rewrite engine were off.
ProxyHTMLEnable On
ProxyHTMLExtended On
# determine encoding(UTF-8) by reading META tags.
ProxyHTMLMeta On
ProxyHTMLInterp Off
# the size of the buffer for manipulating HTML, 256k here.
ProxyHTMLBufSize 256000
# force HTML5 :)
ProxyHTMLDocType "<!DOCTYPE html>"
# mapping URL in HTML content
ProxyHTMLURLMap http://server.company.com/ /
ProxyHTMLURLMap https://server.company.com/ /
# turn off gzip compression.
RequestHeader unset Accept-Encoding
##########################
# reverse proxy settings #
##########################
# redirect / to welcome page.
RewriteRule ^/$ http://%{SERVER_NAME}/portal [R]
# force HTTPS on the URL.
RewriteCond %{HTTPS} !=on
RewriteRule ^/auth/(.*) https://%{SERVER_NAME}/auth/ [R,NE]
ProxyPass /auth https://server.company.com/auth
ProxyPassReverse /auth https://server.company.com/auth
ProxyPassReverse /auth https://server.company.com:443/auth
####### put each application mapping here #######
ProxyPass /portal http://server.company.com/portal
ProxyPassReverse /portal http://server.company.com/portal
ProxyPassReverse /portal http://server.company.com:80/portal
ProxyPassReverse /portal https://server.company.com/portal
ProxyPassReverse /portal https://server.company.com:443/portal
#################################################
# for security reason, forbidden all other URL(s)
ProxyPass / "!"
<Proxy *>
Require all granted
</Proxy>
</IfModule>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment