I have an apache server running on Ubuntu, and it runs without issue. Apache currently serves static webpages, and is configured with several Vhosts. The problem is trying to configure a Vhost to proxy to a node.js backend. Everything I have tried has not has any noticeable results, and simply displays the apache filesystem as if no proxy exists at all.
I have tried configuring the Vhosts is many different ways, including copying word for word what was said on multiple tutorials from digitalocean. I expect that when I enter api.rpgrat.org into the address bar of a web browser that I will get the output of the node.js server instead of the apache file system viewer. I have no idea what I have done wrong currently, so any help is greatly appreciated.
The full 000-defaults.conf is below, and does not throw any errors when I start or restart apache, and all of the other vhosts work as intended (rpgrat.org goes to the main page, play.rpgrat.org goes to the file system currently, chess.rpgrat.org redirects to rpgrat.org/chess, etc.):
ServerAdmin administrator@localhost
DocumentRoot /web/
<VirtualHost *:80>
ServerName www.rpgrat.org
ServerAlias rpgrat.org https://rpgrat.org
DocumentRoot /web/static
ErrorLog /web/logs/main_errors.log
CustomLog /web/logs/main_other.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName play.rpgrat.org
DocumentRoot /web/node
ErrorLog /web/logs/node_errors.log
CustomLog /web/logs/node_other.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName chess.rpgrat.org
RewriteEngine on
Redirect / https://rpgrat.org/chess
</VirtualHost>
#problem is this one \/
<VirtualHost *:80>
ServerName api.rpgrat.org
DocumentRoot /web/public
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
proxyPass / http://localhost:8000/
proxyPassReverse / http://localhost:8000/
Header set Access-Control-Allow-Origin "*"
ErrorLog /web/logs/public_errors.log
CustomLog /web/logs/public_other.log combined
</VirtualHost>
The backend is working correctly, and is running on localhost:8000
; and this can be easily tested with curl localhost:8000
giving the output API Backend
, as it should. The code for the node server is below:
const http = require("http");
const host = 'localhost';
const port = 8000;
const requestListener = function (req, res) {
res.writeHead(200);
res.end("API Backend\n");
};
const server = http.createServer(requestListener);
server.listen(port, host, () => {
console.log(`API Server is running on http://${host}:${port}`);
});
I'm going to update this to show what I have done in an attempt to fix this so far, I have reinstalled all necessary apache modules, which I'll list here along with the commands I used to install them.
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
Of course I have also restarted apache2 after every change, and have the necessary ports open in the UFW, which I'll include below in case that is useful in some way:
80/tcp ALLOW Anywhere
443 ALLOW Anywhere
8000 ALLOW Anywhere
I also did some testing with lynx on my server environment, and I can once again confirm that connecting to localhost
brings up my main page, as expected, connecting to localhost:8000
or api.localhost:8000
brings up the node.js server, but api.localhost
redirects to the apache filesystem for seemingly no reason, it just appears that proxyPass is doing nothing at all. The error log file is clean save for a few blocked fetch requests I made before enabling CORS butfor good measure I will include the error log as well:
[Tue Jan 23 03:35:46.328697 2024] [authz_core:error] [pid 140060:tid 140348785419840] [client 137.184.150.232:59380] AH01630: client denied by server configuration: /web/public/server-status
[Tue Jan 23 03:35:47.993133 2024] [authz_core:error] [pid 140059:tid 140347770394176] [client 134.122.89.242:34688] AH01630: client denied by server configuration: /web/public/server-status
The main log simply logs the hundreds of test connections I have made in an attempt to fix this problem, and is much too long to include here.
I did end up figuring this out, my SSL config was mapped to port 80 instead of port 443. I'm not sure why Apache's logs didn't catch this, but that appears to have been the issue. If you're having this issue, make sure you set up SSL correctly and use the right ports!