简体   繁体   English

Node.js通过Amazon EC2上的Apache进行代理

[英]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. 我正在尝试在我的EC2实例上为我的Node.js服务器设置代理,所以我可以通过http://*.amazonaws.com/node访问它,其中*是URI的其余部分。 I've set up the proxy by editing /etc/httpd/conf/httpd.conf with the following: 我通过使用以下命令编辑/etc/httpd/conf/httpd.conf设置代理:

<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: 我的Node.js server.js文件如下所示:

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. 因此,当我启动并运行所有内容时,我可以访问/ node ,但是,Node.js的/ public目录没有被用作Document的根目录,所以我得到任何文件index.html包含404s因为它假设它在/ public目录。 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. 例如,Firebug报告了一个404的http://*.amazonaws.com/javascripts/rails.js和另外3个文件,这意味着它没有访问Node.js的/ public目录。

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 . 值得注意的是,如果我编辑index.html文件中的路径,一切正常,但我宁愿不必这样做......如果我在httpd.conf中取出ProxyPass配置,只需访问节点来自http://*.amazonaws.com:3000服务器,它可以工作......但理想情况下,我不想这样做并能够做/节点

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? 我想知道的是,我的代理配置是否正确,如果没有,我该如何修复它,以便当我访问/ node时 ,所有请求的文件都会被自己重定向?

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: 但是,如果您希望apache处理静态请求,则这是用于生成ProxyPass异常的apache配置语法:

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. 您还需要确保设置了DocumentRoot ,但是这应该通过任何对javascript目录的请求传递给常规apache,它将以您配置的任何方式处理对该目录的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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