Question

Proxy/reverse proxy on an https site doesn't seem to be working.

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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

I don’t seem to be able to edit or delete this question. So here’s the setup for my ssl proxy file.

    ProxyPreserveHost On
    ProxyPass /search http://localhost:3000/search
    ProxyPassReverse /search http://localhost:3000/search
Bobby Iliev
Site Moderator
Site Moderator badge
March 20, 2024

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:

  1. Make sure that your ProxyPass and ProxyPassReverse directives are correctly set up in your Apache configuration. The syntax should look something like this:

    ProxyPass /search http://localhost:3000/search
    ProxyPassReverse /search http://localhost:3000/search
    

    The directives are within the correct <VirtualHost> block or in the appropriate configuration context.

  2. 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.

  3. 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.

  4. 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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel