0

I've got some websites in the local network, which have no access to the internet. So I want to set up one machine which has the access, and use it as a reverse proxy.

My apache config looks like this:

ProxyPass "/website1" "http://192.168.0.1/website1"
ProxyPassReverse "/website1" "http://192.168.0.1/website1"

So when I access my public domain /website 1 it redirects me to the website1, but when i click something on there which forwards me to something like /website1/about, it doesn't work, because the sourcecode still says to go to http://192.168.0.1/website1/about, which is obviously not possible from outside of the local network.

So how do I get Apache to forward all files and rewrite the paths?

Or an even better question, is there something better than apache to do an reverse proxy?

complete conf: http://pastebin.com/Mhuv7YzM

3
  • Apache is great for reverse proxy. My question is how the rest of the VirtualHost looks like, can you provide us with it?
    – Orphans
    Feb 16, 2017 at 13:28
  • @Orphans added, but really nothing special there
    – lemon
    Feb 16, 2017 at 13:32
  • Please check my answer
    – Orphans
    Feb 16, 2017 at 13:41

4 Answers 4

1

You have two options depending on what you backend does.

If the backend server modifies html links with the name of the requested host you can just add:

ProxyPreserveHost on

If you want to modify the contents of "fixed" htmnl links inside the responses you will also need "mod_proxy_html" functionality, which is a mod_proxy submodule specific for this.

mod_proxy_html

0

You don't. ProxyPassReverse is only intended to rewrite redirects, not paths somewhere in the body of files. That would require pretty much complete knowledge of the content format, like HTML, SOAP, whatever, to know where paths are to be expected and replaced (like in <a href="..."> for HTML, but also <link>, <script>, …).

What you probably want to do is simply setting up different vHosts for different reverse proxied websites, so that no rewriting of relative paths is necessary. Of course, if some links contain the domain (as seems to be the case, if I understand your question correctly), it won't work that way either and you "simply" have to configure the website on the internal host to use the correct, external domain name in links.

0

I just use nginx now, it works flawless.

sub_filter_types        text/css;
sub_filter_once         off;
sub_filter              '192.168.0.1'  'proxy.mydomain.com';
proxy_set_header        Accept-Encoding "";

location /website1 {
    proxy_pass              http://192.168.0.1/website1;
}

location /website2 {
    proxy_pass              http://192.168.0.2/website2;
}

may you even want to use caching for faster access, then add this:

proxy_cache_path /var/www/cache levels=1:2 keys_zone=nginx:10m;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 10m;
proxy_cache nginx;

just make sure to create the path /var/www/cache or set another existing one

-3

You have forgotten enabling "RewriteEngine" Be sure that you have enabled mod_proxy, mod_proxy_http and mod_rewrite.

Adding this will propably solve it.

    ProxyRequests off
    RewriteEngine on
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>

And also thoose line should look like this:

ProxyPass "/website1" "http://192.168.0.1/website1"
ProxyPassReverse "/website1" "http://192.168.0.1/website1"
RewriteRule ^/website1$ http://%{HTTP_HOST}/website1 [L,R=301]
11
  • Thanks for that, but it's not working. Source code still looks like <script type="text/javascript" src="192.168.0.1/website1/js/jquery-1.10.0.min.js"></…>
    – lemon
    Feb 16, 2017 at 13:41
  • That's why you have to use mod_rewrite also.
    – Orphans
    Feb 16, 2017 at 13:44
  • What modules habe you enabled?
    – Orphans
    Feb 16, 2017 at 13:46
  • @Orphans mod_rewrite does not modify the delivered content, it rewrites the paths in the requests that are forwarded to the internal server.
    – jplitza
    Feb 16, 2017 at 13:46
  • all these mods are enabled.
    – lemon
    Feb 16, 2017 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .