logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Reverse Proxy woes with Node/express/ejs application
Author
karlkras



Joined: 19 Aug 2024
Posts: 3
Location: US, McMinnville

PostPosted: Mon 19 Aug '24 20:08    Post subject: Reverse Proxy woes with Node/express/ejs application Reply with quote

Good morning.
I have what I hope is a relatively basic question concerning reverse proxy configuration.
I have a nodejs/express/ejs application that is an 100% backend web application.
In my development environment I'm running this on port 9001, and is working as I would expect. This image will show that it's connecting to the web file and pulling the associated dependencies as I would expect:
[img]https://drive.google.com/file/d/11DAd2sB5a8CRJwEYxhL_gANBI3AiKjYw/view?usp=drive_link[/img]

These are in context to localhost:9001 and no problem.

Now I'd like to front this with my apache server by adding a reverse proxy in front of it... so I add this to my server configuration:

Code:
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass /onboard http://localhost:9001
    ProxyPassReverse /onboard http://localhost:9001
</VirtualHost>


and this is broken. While going here ... localhost/onboard will hit the main page, the associated dependencies are attempting to be found at the root of localhost, i.e., localhost/ as this image (sorry, I really don't know that the img tag is supposed to do... apparently nothing):
[img]https://drive.google.com/file/d/1NINkFDL2q02K6aG4Qbduxpj0mNSYD7EF/view?usp=drive_link
[/img]

any idea on why this is happening and how I can fix it?

thanks,
Karl
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7368
Location: Germany, Next to Hamburg

PostPosted: Mon 19 Aug '24 23:24    Post subject: Reply with quote

Hello!
it is because of the path. You use /onboard instead of /
And the missing files are looked at /styles/...

You can either
- change the reverse proxy to /
- or use mod_proxy_html to change the html
- or fix the paths in your node files
- or use mod_rewrite
Back to top
karlkras



Joined: 19 Aug 2024
Posts: 3
Location: US, McMinnville

PostPosted: Tue 20 Aug '24 18:45    Post subject: Reply with quote

James Blond wrote:
Hello!
it is because of the path. You use /onboard instead of /
And the missing files are looked at /styles/...

You can either
- change the reverse proxy to /
- or use mod_proxy_html to change the html
- or fix the paths in your node files
- or use mod_rewrite


Thanks, so I guess I don't quite get the point of the reverse proxy.
From what documentation I've found, this should provide the means to provide a routing gateway to possibly multiple services running on the same system on different ports. So for example (the app I specified above running on port 9001 and another possibly like :
Code:
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass /another http://localhost:9025
    ProxyPassReverse /another http://localhost:9025
</VirtualHost>


Having to use / would imply I can only have one such service exclusively which isn't what I want.
I take it that there must be much more configuration needed than what would seem obvious.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7368
Location: Germany, Next to Hamburg

PostPosted: Tue 20 Aug '24 23:26    Post subject: Reply with quote

The problem is that path in your HTML.
Back to top
karlkras



Joined: 19 Aug 2024
Posts: 3
Location: US, McMinnville

PostPosted: Fri 23 Aug '24 20:46    Post subject: Reply with quote

James Blond wrote:
The problem is that path in your HTML.


Sorry James, but that's just not helping.
What's the problem? I can't simply use a forward slash, the resources are at the root of the port it's running on.
I need to name the sub root so it can identify with the intended app:port combination don't I?
Simply using <host>/ limits only one app to ever be referenced. It simply can't work that way.

The main page is found just fine using the /onboard specifier, but the resources are assuming / , which is incorrect.
If there is other configuration needed to achieve this, I'm all ears, but all references on how to do this is stated exactly what I've tried.
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 346
Location: UK

PostPosted: Sun 25 Aug '24 15:59    Post subject: Reply with quote

James has clarified the basis of your problem, and you've equally outlined the same, when you say:

karlkras wrote:
Simply using <host>/ limits only one app to ever be referenced. It simply can't work that way.

Well conceptually, it does, since irrespective of the port, your deployed application is currently tied to the site root URL.

As it stands, your ProxyPass and ProxyPassReverse statements will only cover request and response headers; they won't adjust embedded URL paths in response bodies. So for example, a request URL for /styles/app.css won't get rewritten to /onboard/styles/app.css. Hence his suggestion to use output filter mod_proxy_html to do this.

So if you want to reference your application at /onboard rather than /, you'll need to adjust the URL's in the response bodies. If you do go down this route, you'll need to rewrite any other sub-folder paths your deployed app uses apart from /styles, e.g. /images. Although somewhat old, the following site gives a good overview of how to use the mod_proxy_html module http://www.apachetutor.org/admin/reverseproxies

The alternative (possibly easier) option might be to reconfigure your deployed app on port 9001 to be below /onboard rather than /.
Back to top


Reply to topic   Topic: Reverse Proxy woes with Node/express/ejs application View previous topic :: View next topic
Post new topic   Forum Index -> Apache