I'm setting up a nodejs http server on 8000 and Apache on 80 in Raspbian.
The NodeJS would serve the *.njs file, to respond all request. (njs file is same as php. I made it looks like modules that return onRequest, onUpgrade and onConnect).
The Apache would serve any files' type such as html, php, image, and etc.
Apache would be the main server to serve any files in there. And *.njs files are in the http folder too. While there is a connection to request any *.njs files, it would forwarding (not redirecting) to nodejs http server and then it would return to client again.
Simply : Every request should be pass from Apache, then it forward to and handled by NodeJS http server, then it would return back to client.
How could I do that?
*The NodeJS HTTP Server has done right and no problem when I made request to it.
While I search on Internet, I found that Proxy could help me.
I have activate the proxy modules. Had setting to 000-default.conf
. Using ProxyPass
and ProxyPassMatch
could pass the connection to NodeJS http server, but it couldn't return back. Then, I tried to use ProxyPassReverse
. But it could only serve a route, not a specific multiple route.
I had tried ProxyRemote
, SetHandler
, <Proxy *>
, <Location ~ ".*">
and still not working.
Here all that I have done in 000-default.conf
.
First Try,
<VirtualHost *:80>
ProxyPassMatch "\.njs$" "http://0.0.0.0:8000"
ProxyPassReverse "/*" "http://0.0.0.0:8000"
ProxyRemote "/*" "http://0.0.0.0:8000"
SetHandler "http://0.0.0.0:8000"
</VirtualHost>
Second Try,
<VirtualHost *:80>
<Location ~ "\.njs$">
ProxyPass "http://0.0.0.0:8000"
ProxyPassReverse "http://0.0.0.0:8000"
ProxyRemote "http://0.0.0.0:8000"
SetHandler "http://0.0.0.0:8000"
</Location>
</VirtualHost>
Third Try,
<VirtualHost *:80>
<Proxy "*">
ProxyPass "http://0.0.0.0:8000"
ProxyPassReverse "http://0.0.0.0:8000"
ProxyRemote "http://0.0.0.0:8000"
SetHandler "http://0.0.0.0:8000"
</Proxy "*">
</VirtualHost>
I have tried all of them, I remove, add, and change the route and the command. Some make the error, such as ProxyPass
couldn't use regexp in <Proxy "*">
, ProxyRemote
coudn't be used in <Location>
, ProxyPassReverse
couldn't use regexp. And all are failed to used.
I expect it could forwarding the connection to nodejs http server for *.njs files. I want to use Apache as my main server to server and forwarding and only need NodeJS server to handle the forwarding and response the request. The NodeJS is good enough and hasn't problem. Only Apache to need some settings.
How could I done all of this?