# Reverse proxy pass multiple sites with similar content structure

**URL:** <https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961>\
**Category:** Get Help\
**Tags:** question\
**Created:** [March 16, 2022, 8:36pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961 "2022-03-16T20:36:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandon-biggs](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/brandon-biggs/32/350_2.png) [@brandon-biggs](https://discourse.openondemand.org/u/brandon-biggs)\
**Post date:** [March 16, 2022, 8:36pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/1 "2022-03-16T20:36:04Z")

</div>

Hi,

We’re trying to setup a reverse proxy to an internal site through OnDemand. We want users to be able to go to `ondemand.example.com/<path>/documentation` and it proxies them to `documentation.example.com`. We have gotten this to work with an additional apache configuration ‘location’ block:

```auto
<Location "/documentation"> 
AuthType openid-connect 
Require valid-user 
ProxyPreserveHost on 
ProxyPass https://documentation.example.com/home 
ProxyPassReverse https://documentation.example.com/home 
</Location>

```

However there are a couple of issues. It seems that we have to define a new location block for each of the static folders that `documentation.example.com` has, such as `documentation.example.com\javascript` or `documentation.example.com\styles.`

This would be fine, but we’re concerned about collisions in the static folders if we proxy future content as well. For example, if we proxied `tickets.example.com`, and it is looking for a `\styles` folder, it would collide with the `\styles` folder for `documentation.example.com` as they are both being proxied to `ondemand.example.com\styles`.

We were looking for a solution that would allow us to proxy these sites through a less general URL, such as `ondemand.example.com/rnode/documentation`, which would include all of the forwarded server files such as `ondemand.example.com/rnode/documentation/styles`. This would hopefully prevent conflicts as `tickets.example.com` would be proxied through `ondemand.example.com/rnode/tickets` and the sub folders would follow suit.

We believe there’s a regex way to do some of this with a `<LocationMatch>` block, but we wanted to ask so we could set this up in a way that doesn’t interfere with OnDemand’s apache configuration and do this in the most secure way possible, ie behind authentication, ssl, etc.

We also noticed that some sites don’t like to proxy pass, so we were also wondering if there was an easy way to test if the other host was setup correctly to allow reverse proxy passes?

We have found similar questions on the discourse but they didn’t seem to solve our problem exactly - [How to add a proxy rule in the ood\_portal.yml file?](https://discourse.openondemand.org/t/how-to-add-a-proxy-rule-in-the-ood-portal-yml-file/488)

Thanks.

---

<div class="post-metadata">

**Author:** ![travert](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/travert/32/3074_2.png) [@travert](https://discourse.openondemand.org/u/travert)\
**Post date:** [March 17, 2022, 3:24pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/2 "2022-03-17T15:24:57Z")

</div>

I would recommend doing a virtual host for the `documentation.example.com` to serve those documents from that is separate from OnDemand.

@tdockendorf do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![tdockendorf](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/tdockendorf/32/202_2.png) [@tdockendorf](https://discourse.openondemand.org/u/tdockendorf)\
**Post date:** [March 17, 2022, 4:46pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/3 "2022-03-17T16:46:05Z")

</div>

I think it’s better to use Rewrite rules instead of proxy. Neither solution will work with ood-portal-generator so either direction would require either not using ood-portal-generator or patches to ood-portal-generator we do plan to make to allow for more customization of the OnDemand Apache config.

Example rewrite rule:

```auto
RewriteRule "^/documentation/(.+)" "https://documentation.example.com/$1" [R=301,NE,L]

```

This example is mostly pulled from Apache docs: [Redirecting and Remapping with mod\_rewrite - Apache HTTP Server Version 2.4](https://httpd.apache.org/docs/2.4/rewrite/remapping.html#movehomedirs)

Not sure what benefits exist using a proxy method over simple redirects. The rewrite rule above would go in LocationMatch block. If the goal is to have OnDemand VHost be the entry point, then you must modify OnDemand’s ood-portal.conf.

It could be possible to make this work with existing ood-portal-generator by putting that rewrite rule into `ssl` array since that array is injected as-is into Apache configs. However that SSL array goes above all the Locations so you’d have to enforce authentication on the sites you redirect to, and if you use SSO, users won’t have to re-authenticate, so things like Keycloak, if both VHosts use the same instance, could see authentication from one as valid for another vhost.

---

<div class="post-metadata">

**Author:** ![msgambati-INL](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/msgambati-inl/32/935_2.png) [@msgambati-INL](https://discourse.openondemand.org/u/msgambati-INL)\
**Post date:** [March 18, 2022, 3:25pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/4 "2022-03-18T15:25:33Z")

</div>

Hey guys,

We appreciate the feedback. I’m not a web developer or apache person, so please excuse my amateurish questions 🙂

Looking into this some, using the RewriteRule, we can get it to work for the main page, but how do you handle the URLs on the page that we “proxied” to? Since the ondemand side is expecting all urls to begin with ^/documentation, but all the URLs on the “proxied” page do not. Can we use a RewriteBase or something else?

As for the virtual host, from my understanding we would need to have an additional hostname that is resolvable for that to work, which we do not. We need this to work via [ondemand.example.com](http://ondemand.example.com) namespace.

Also, adding the working RewriteRule to a LocationMatch section seems to break it, which does not make any sense to me. I now have a new found appreciate for the complexities of apache.

Here is the rule we have that works if we modify the urls to always contain /documentation at the beginning:

```auto
RewriteRule "^/document(.*)" "https://example.com/$1" [P]

```

Here is one attempt to prepend /document to everything:

```auto
RewriteRule "^/document(.*)" "https://example.com/$1" [P]
RewriteCond %{HTTP_HOST} "^https://example.com/document/$1"
RewriteRule "^example.com" "https://example.com/document/$1" [R]

```

Thanks again,

Matt

---

<div class="post-metadata">

**Author:** ![tdockendorf](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/tdockendorf/32/202_2.png) [@tdockendorf](https://discourse.openondemand.org/u/tdockendorf)\
**Post date:** [March 18, 2022, 4:51pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/5 "2022-03-18T16:51:28Z")

</div>

So the way this rule works:

```auto
RewriteRule "^/document(.*)" "https://example.com/$1" [P]

```

Is if it’s part of [ondemand.example.com](http://ondemand.example.com), any URL beginning with /document/something on that host will redirect to [example.com/something](http://example.com/something). That is not going to be proxying involved, it’s a redirect to new website. You don’t need to put this into a LocationMatch section for it to work. I’m not sure I follow how or why proxying would be needed, based on the original desired result, all you should need is a redirect.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [September 14, 2022, 4:51pm UTC](https://discourse.openondemand.org/t/reverse-proxy-pass-multiple-sites-with-similar-content-structure/1961/6 "2022-09-14T16:51:51Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
