Node.js proxies through Apache on Amazon EC2

I am trying to configure a proxy server 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 installed the proxy server by editing /etc/httpd/conf/httpd.conf as follows:

 <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 is as follows:

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

So, when everything works and works for me, I can access / node , however, the Node.js / public directory is not used as the root directory of the document, so I get 404s for any index.html file, because it accepts it in the directory / public . For example, Firebug reports 404 for http://*.amazonaws.com/javascripts/rails.js and 3 other files, which means that it does not fall into the Node.js / public directory.

It’s good to note that if I edit the paths in the index.html file, everything works, but I would prefer not to do this ... also if I select the ProxyPass configuration in httpd.conf and just access the node server from http://*.amazonaws.com:3000 , it works ... but ideally I wouldn’t want to do this and could do / node .

I want to know if my proxy is configured correctly, and if not, how can I fix it, so when I access / node , all the requested files are redirected themselves?

+4
source share
1 answer

I agree with the commentators that if you use express-static middleware, you may not configure it correctly.

At the same time, if you want apache to handle static requests independently, this is the apache configuration syntax for creating a ProxyPass exception:

 ProxyPass /javascript/ ! 

You also need to make sure that you have the DocumentRoot set, but it must go through any requests to the javascript directory in regular apache, which will handle requests to this directory in any way that you configured.

+1
source

Source: https://habr.com/ru/post/1499890/


All Articles