简体   繁体   中英

Node.js proxy through Apache on Amazon EC2

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM