Skip to content

Instantly share code, notes, and snippets.

@beije
Last active February 26, 2021 18:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beije/5689935 to your computer and use it in GitHub Desktop.
Save beije/5689935 to your computer and use it in GitHub Desktop.
An example apache virtual host config for internal proxying. A wonderous hack if you lack control of DNS servers and need to test a site on a device that doesn't let you modify the hosts file.
<VirtualHost *:80>
ServerName 10.0.0.10
# Set url to proxy
ProxyPass / http://hosts.domain.dev/
ProxyPassReverse / http://hosts.domain.dev/
# Set location
<location />
# Set url
ProxyPass http://hosts.domain.dev/
# Ouput html from proxy filter
SetOutputFilter proxy-html
# Add referer hack (if the site uses referrer as security)
Header add referer "http://hosts.domain.dev"
RequestHeader set referer "http://hosts.domain.dev"
# Overwrite html, exchange urls with proxied (like href, src, etc.)
ProxyHTMLExtended On
ProxyHTMLURLMap http://hosts.domain.dev http://10.0.0.10
# For items that use style="background-image:url()"
ProxyHTMLEvents style
# You can add more url maps to overwrite if there are subdomains
# that you want/need to override
ProxyHTMLURLMap http://static.domain.dev http://10.0.0.10
# Rewrite Cookie domain if the site uses sessions as an identifier
# i.e. PHPSESSID
ProxyPassReverseCookieDomain .domain.dev 10.0.0.10
</location>
</VirtualHost>
@luigicascio
Copy link

Hi i have a problem with this configuration ,
the proxy is done, but the link replace don't work , can you hel me?
This is the configuration:
ServerName www.reart.it
ServerAlias reart.it

Set url to proxy

ProxyPass /shop http://shop.talya.it/
ProxyPassReverse /shop http://shop.talya.it/

Set location

<location /shop>
# Set url
ProxyPass http://shop.talya.it/

    # Ouput html from proxy filter
    SetOutputFilter proxy-html

    # Add referer hack (if the site uses referrer as security)
    Header add referer "http://shop.talya.it"
    RequestHeader set referer "http://shop.talya.it"
    RequestHeader set custom_head "proxy"

    # Overwrite html, exchange urls with proxied (like href, src, etc.)
    ProxyHTMLExtended On
    ProxyHTMLURLMap http://shop.talya.it  http://reart.it

    # For items that use style="background-image:url()"
    ProxyHTMLEvents style

    # You can add more url maps to overwrite if there are subdomains
    # that you want/need to override
    ProxyHTMLURLMap http://static.domain.dev  http://reart.it

    # Rewrite Cookie domain if the site uses sessions as an identifier
    # i.e. PHPSESSID
    ProxyPassReverseCookieDomain .talya.it reart.it

@marcelodelta
Copy link

Hello, how are you ?

This solution looks a lot like something I need to do.

I have a domain that I need to point to another application in a remote domain.

However, access to the remote domain requires security of origin.

Can you help me?

I'm doing this but it does not work.

https://stackoverflow.com/questions/56660258/how-to-forward-a-domain-to-the-remote-host-using-proxyreverse-apache

Grateful for the attention.

@beije
Copy link
Author

beije commented Jun 19, 2019

@marcelodelta you also need to rewrite the URLs.

In the stackoverflow thread you specifically say "However the page is fully loaded, missing some requests.", am I right to assume that it's about asset files?

In that case, you need to use ProxyHTMLURLMap so it'll change the contents and rewrite the proxied domain to the proxy's domain.

@marcelodelta
Copy link

A json request.

@marcelodelta
Copy link

marcelodelta commented Jun 19, 2019

How to use ProxyHTMLURLMap

Thanks for listening.

Can I send you more details?

@DieselDriver
Copy link

Hello Benjamin,

why does the reverse proxy does not work for e.g. https://medium.com/dronehub?
The index page works, also the replacing of href but the submenus only show an error 404.

Is there any other security feature used by medium.com or is it a problem of the header which will be returned by the reverse proxy?
I see that medium.com uses json calls which have other behavior than when the website will be opened through the medium.com URL (the network sniffer contains different requests) .

I hope you have an idea.

Thanks.

@beije
Copy link
Author

beije commented Oct 23, 2019

@DieselDriver I can't say why it's not working without setting it up, but my initial hunch would be that not all the requests are made against medium.com but through other hosts, e.g. cdn's etc. You'd probably have to set up proxies against those URL's as well.

@DieselDriver
Copy link

The relevant request for the main content is made against medium.com and I think they check the referer in other way as usual.
It's an interessting problem - this is the first website that makes troubles with a reverse proxy. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment