I’m experiencing a 502 Proxy Error on my Apache server (Ubuntu) when trying to set up a reverse proxy to my Node.js application running on localhost port 3000. Apache and Node.js are on the same server. Apache’s mod_proxy
and mod_proxy_http
modules are enabled, and the proxy configuration directives ProxyPass
and ProxyPassReverse
are pointing to http://localhost:3000/search
. The Node.js application runs well independently and listens on port 3000, as confirmed by netstat
. However, when accessed via Apache, it results in a 502 error. The Apache error log indicates “Connection refused” errors but no further specifics are given. I’ve ensured that there are no firewall issues blocking the connection between Apache and Node.js. Any insights or suggestions to resolve this would be greatly appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
I don’t seem to be able to edit or delete this question. So here’s the setup for my ssl proxy file.
Hey!
The 502 Proxy Error you’re encountering suggests that Apache, acting as a reverse proxy, is unable to communicate with your Node.js application.
The error indicates that while Apache is configured to forward requests to the Node.js server, it’s not getting the expected response. Here are some things that I would recommend stating with:
Make sure that your
ProxyPass
andProxyPassReverse
directives are correctly set up in your Apache configuration. The syntax should look something like this:The directives are within the correct
<VirtualHost>
block or in the appropriate configuration context.You mentioned that
netstat
confirms Node.js is listening on port 3000. It’s good to double-check this and ensure that the Node.js application is not binding to a specific IP address (like 127.0.0.1). It should be listening on all interfaces or specifically on the localhost interface.The “Connection refused” error typically means that the attempt to connect to the Node.js server was unsuccessful. This could be due to the Node.js server not running or listening on the expected port or interface, or due to network issues (though you mentioned firewall issues are ruled out). You can check the logs at
/var/log/apache2/error.log
.Check the logs of your Node.js application to ensure that there are no internal errors preventing it from responding to Apache’s requests.
If you’ve checked these points and the issue persists, providing more specific logs or configuration details could help in further diagnosing the problem.
Best,
Bobby