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?

4

1 回答 1

1

我同意评论者的观点,如果您使用的是 express 静态中间件,那么您可能错误地配置了 express。

但是,如果您希望 apache 无论如何都处理静态请求,这是用于产生 ProxyPass 异常的 apache 配置语法:

ProxyPass /javascript/ !

您还需要确保您有一个DocumentRoot集合,但这应该将任何对 javascript 目录的请求传递给常规 apache,后者将以您配置的任何方式处理对该目录的请求。

于 2013-11-20T05:44:28.673 回答