3

I'd like to serve a node app as a path of my domain, like this: http://example.com/foo will actually serve the node app running on port 8080.

I've looked into ProxyPass and ProxyPassReverse:

ProxyPass /foo http://localhost:8080
ProxypassReverse /foo http://localhost:8080

This will serve the index.html of the node app, but I get errors in my console about all the assets:

Failed to load resource: the server responded with a status of 404 (Resource not found) http://example.com/styles/4742a4e8.main.css

I thought the ProxyPassReverse directive would take care of that, but apparently not. I have very limited knowledge about apache. Any bright ideas on how to solve this?

Disclaimer: yes, I've looked into many nodejs combined with apache questions, but none of them address the problem of using a subdirectory in the url

3

I'm gussing that http://example.com/styles/4742a4e8.main.css is actually a file on your node JS application, so refers to http://localhost:8080/styles/4742a4e8.main.css, but is being reference in the index.html from your node app as /styles/4742a4e8.main.css

With the proxy mapping what is happening is that when you request

http://example.foo/foo/ it's sending a request which is returning http://localhost:8080/index.html as is. Any references within index.html aren't modified, so when the browser requests componenets it's requesting http://example.com/styles/4742a4e8.main.css but the file is only really accessible via http://example.com/foo/styles/4742a4e8.main.css

if /styles/ isn't used within example.com you could add

ProxyPass /styles http://localhost:8080/styles
ProxypassReverse /styles http://localhost:8080/styles

But this may become cumbersome if you have lots of directories.

Another approach would be to use relative paths on your node app. So instead of index.html referencing /styles/4742a4e8.main.css it referenced styles/4742a4e8.main.css (no leading slash). This might become cumbersome with nested paths in your node app.

A further solution may be to modify your node.js app to be fully run under localhost:/foo so the directory mapping is the same.

I'm not sure any of these solutions are ideal for your use case, but they will hopefully point you in the right direction.

2
  • Thanks for the extensive answer! I guess I'll be going for the relative paths, if possible. Won't accept it yet, want to see if any other answers are given. – Creynders Mar 12 '14 at 11:49
  • 1
    Totally understand, I can't see any of them being particularly pleasant. I take it that requesting http://example.foo/foo/styles/4742a4e8.main.css does give you the correct file, not a 404, so the error is at least identified? – DorianFM Mar 12 '14 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.