4

I'm trying to set up a proxy for my Node.js server on my EC2 instance, so I can access it through something like http://*.amazonaws.com/node, where * is the rest of the URI. I've set up the proxy by editing /etc/httpd/conf/httpd.conf with the following:

<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>
ProxyPass /node http://*.amazonaws.com:3000
ProxyPassReverse /node http://*.amazonaws.com:3000

My Node.js server.js file looks like this:

var port = process.env.PORT || 3000;
var host = '*.amazonaws.com' || process.env.HOST || '127.0.0.1';

So when I have everything up and running, I can access /node, however, the Node.js's /public directory is not being used as the Document's root directory, so I get 404s for any file index.html includes because it's assuming it's in the /public directory. For example, Firebug reports a 404 for http://*.amazonaws.com/javascripts/rails.js and 3 other files, which means this is not hitting the Node.js's /public directory.

It's good to note if I edit the paths in the index.html file, everything works, but I would rather not have to do that... also, if I take out the ProxyPass config in httpd.conf, and just access the node server from http://*.amazonaws.com:3000, it works... but ideally, I'd like to not have to do that and be able to do /node.

What I want to know is, is my proxy configured correctly, and if not, how do I go about fixing it so when I access /node, all of the requested files get redirected themselves?

3
  • What's your node directory structure? Is the index.html file in public? Could you post your node code (or at least the main file, usually app.js if you're using express for example) Commented Oct 3, 2013 at 9:37
  • 1
    The fact that requests don't hit the public (static files) directory is not necessarily due to a bad proxy configuration. What is the order of your middleware or where did you put app.use(express.static(__dirname + '/public')); ? Commented Oct 30, 2013 at 21:04
  • As explained in my other comment, I'm using CompoundJS as the scaffolding/MVC framework. It makes use of Express, but it basically abstracts all of that away from me. I'll do some digging around and get back to you on that. Commented Nov 20, 2013 at 21:18

1 Answer 1

1

I agree with the commenters that it's possible, if you're using express static middleware, that you may have misconfigured express.

In the event, however, that you want apache to handle static requests regardless, this is the apache configuration syntax for making a ProxyPass exception:

ProxyPass /javascript/ !

You would also need to make sure that you have a DocumentRoot set, but this should pass thru any requests to the javascript directory to regular apache, which will handle requests to that directory in whatever way you've configured.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, ok. I am using CompoundJS, which does use Express. I'll have to look into this when I get a chance.
I have solved it similarly in nginx... it dealt with using alias instead of root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.