nesreka nesreka - 4 months ago 61
AngularJS Question

How to make Apache proxy to NodeJS correctly?

I'm developing a NodeJS application with AngularJS.
For testing I want to host it on a webserver that runs an apache2 webserver.
Googling and Try-And-Error brought me to the fact that I need to simply make Apache forward the requests with the proxy module:

<Location /someurl>
ProxyPass http://mydomain:3000/
ProxyPassReverse http://mydomain:3000/
</Location>


But unfortunately, I am not able to see the page.
Accessing someurl gives me a blank pages, where no javaScript is loaded.

Node debug log:
GET / 200 1.680 ms - 1687


When I access the server via port 3000 I get the following log:

GET / 304 53.814 ms - -
GET /javascripts/directives.js 200 14.369 ms - 6521
GET /javascripts/services.js 200 8.532 ms - 2054
GET /stylesheets/bootstrap.min.css 304 4.173 ms - -
GET /stylesheets/lmm.css 304 4.131 ms - -
GET /javascripts/jquery.min.js 304 4.203 ms - -
GET /javascripts/bootstrap.min.js 304 2.060 ms - -
GET /javascripts/angular.min.js 304 2.486 ms - -
GET /javascripts/angular-route.min.js 304 2.562 ms - -
GET /javascripts/angular-translate.min.js 304 2.643 ms - -
GET /javascripts/app.js 304 2.526 ms - -
GET /javascripts/controller.js 304 2.768 ms - -
GET /javascripts/translations.js 304 1.368 ms - -
GET /partials/footer.html 304 2.391 ms - -
GET /partials/home.html 304 2.202 ms - -
GET /fonts/glyphicons-halflings-regular.woff 304 1.602 ms - -


Here is everything relevant from the acces.log:

myIP - - [13/Jan/2015:10:01:19 +0100] "GET /someurl HTTP/1.1" 200 852 "-"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /stylesheets/bootstrap.min.css HTTP/1.1" 404 513 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /stylesheets/lmm.css HTTP/1.1" 404 504 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/jquery.min.js HTTP/1.1" 404 509 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/bootstrap.min.js HTTP/1.1" 404 513 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular.min.js HTTP/1.1" 404 510 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular-route.min.js HTTP/1.1" 404 517 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular-translate.min.js HTTP/1.1" 404 520 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/controller.js HTTP/1.1" 404 509 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/app.js HTTP/1.1" 404 503 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/directives.js HTTP/1.1" 404 510 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/services.js HTTP/1.1" 404 507 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/translations.js HTTP/1.1" 404 511 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/bootstrap.min.js HTTP/1.1" 404 512 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular.min.js HTTP/1.1" 404 510 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular-route.min.js HTTP/1.1" 404 516 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/angular-translate.min.js HTTP/1.1" 404 520 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/app.js HTTP/1.1" 404 502 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/controller.js HTTP/1.1" 404 509 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/directives.js HTTP/1.1" 404 509 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/services.js HTTP/1.1" 404 507 "http://mydomain/someurl"
myIP - - [13/Jan/2015:10:01:19 +0100] "GET /javascripts/translations.js HTTP/1.1" 404 511 "http://mydomain/someurl"


How do I get apache to correctly forward the request?

Answer

The comment from bennettp123 pointed me in the right direction.

The Apaches access.log file shows that there are 404 errors for the javaScript files and the stylesheets.

Adding them as an Alias before the Location directive fixes the problem:

Alias /javascripts "<path_to_node_project>/public/javascripts"
Alias /stylesheets "<path_to_node_project>/public/stylesheets"
Alias /partials    "<path_to_node_project>/public/partials"
Comments