0

I use Apache to serve several sites to the world on my home server on port 443 using an SSL certificate. Last night I installed a linux binary that serves a site only on a port defined via its config file. It is not possible for me to have Apache serve the site directly.

So this site is hosted on http://127.0.0.1:8081/ but I would like to hide it behind Apache over 443 so that I can access it via https://myserver.duckdns.org/webapp/

I have tried this so far in my site config file but it has not worked:

ProxyRequests off
<Proxy *>
        allow from all
</Proxy>

RewriteEngine On
RewriteRule ^/(.*) /webapp/$1 [P]

<Location /webapp/>
        ProxyPass http://127.0.0.1:8081/
        ProxyPassReverse http://127.0.0.1:8081/
</Location>

Any idea how I can do this?

I thought I could do this using ProxyPass and RewriteRules but I cannot seem to get it to work properly.

Thanks so much in advance!

2
  • 1
    How exactly have you tried to do this so far? Commented Apr 23, 2021 at 12:55
  • @user1686 - Updated question to include what I have tried. Appreciate the help! Commented Apr 23, 2021 at 13:42

1 Answer 1

1

Your rewrite rules a) have the wrong target and 2) are redundant.

RewriteRule with [P] is meant to be used as an alternative to ProxyPass, not together with it. The rewrite destination of a [P] rule would be the remote webapp URL, not a local one. For example, you could use this:

RewriteRule ^/webapp/(.*) http://127.0.0.1:8081/$1 [P]

or this:

ProxyPass /webapp/ http://127.0.0.1:8081/

or this:

<Location /webapp/>
    ProxyPass http://127.0.0.1:8081/
</Location>

(Note: The Apache documentation recommends using ProxyPass whenever possible.)

Your <Proxy *> block is also unnecessary, because it only applies to forward proxying, where the client specifies the proxy destination (which you have disabled).

13
  • Thank you so much! I knew I was not understanding things correctly. I need to do more research here for sure. So I tried your suggestion of just using ProxyPass but for some reason the site does not load as expected. I am going to see if I can post a picture somewhere of what happens so maybe you can help me figure out what could be wrong. Give me a few minutes. Commented Apr 23, 2021 at 14:27
  • See what network requests happen in the browser's DevTools. Chances are the webapp is asking the browser to load resources (JS, CSS, images) from http://127.0.0.1:8081 still, which is obviously not right from the browser's perspective... This might be when ProxyPassReverse becomes necessary. And in some cases, setting ProxyPreserveHost On might be enough to fix the issue (it lets the webapp see that it's being visited through "Host: myserver.duckdns.org"), but not always. Commented Apr 23, 2021 at 14:31
  • Yup! I suspect you are right. I uploaded the images. So here is the site loading correctly under it's originally hosted URL - imgur.com/7lXjj2K. And here it is not loading correctly under the ProxyPass directive - imgur.com/mpxOmLc. One other thing I noticed is that when you put http://<ip-address-of-server>:8081/ into a browser, I notice that the browser is being redirected to http://<ip-address-of-server>:8081/web/dashboard automatically by the application. You can probably see that in the address bar on the pic where the site is loading correctly. Commented Apr 23, 2021 at 14:35
  • And just to add that the site config file only contains ProxyPass /webapp/ 127.0.0.1:8081 Commented Apr 23, 2021 at 14:37
  • Also tried adding ProxyPassReverse and ProxyPreserveHost directives and no change in behavior. Site is still not loading as expecting. The site config file currently contains is -> ProxyPreserveHost On ProxyPass /webapp/ 127.0.0.1:8081 ProxyPassReverse /webapp/ 127.0.0.1:8081 Commented Apr 23, 2021 at 14:48

You must log in to answer this question.

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