Question

Help Needed: Nginx Reverse Proxy to Docker App on App Platform Results in 502 Error

I have a site with Nginx hosted on a Droplet, and I’m trying to create a reverse proxy for a subdirectory (/app) to another web application running on the App Platform in a Docker container. Unfortunately, I keep getting a 502 error no matter what I do. It’s possible to set up another site or domain, but not the one I want to run under the App Platform. Is there something I need to enable in the App Platform to allow a reverse proxy?


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.

Bobby Iliev
Site Moderator
Site Moderator badge
June 2, 2024

Hello,

In addition to what has already been mentioned, I would recommend following these steps in case that you are having any problems with your nginx server and you are unsure on what the problem is:

  • Check your nginx config syntax:
nginx -t

If you get an error, you would need to fix that problem and then you could restart nginx:

systemctl restart nginx
  • If you get Syntax OK when running nginx -t then your confiruation is correct, so I would recommend checking your error logs:
tail -f /var/log/nginx/error.log

The log should contain the actual error rather than the generic 502 error. Feel free to share the output of the log here!

  • Next, check if your Docker container is running and that it is binding to the correct port with:
docker ps -a

Feel free to share the output here and also your Nginx server block reverse proxy config.

And here is also a quick video demo on how to do that as well:

Hope that this helps!

- Bobby

To resolve the 502 error, ensure your Docker container’s app is accessible from the Droplet. Check firewall settings, ensure Nginx is correctly configured with the upstream server details, and verify that the App Platform’s app allows external connections. Also, confirm that Nginx’s proxy settings match the app’s requirements.

alexdo
Site Moderator
Site Moderator badge
May 31, 2024

Heya,

You can create a reverse proxy from Nginx to the URL generated from the App platform.

A similar idea was shared before in the community before:

https://www.digitalocean.com/community/questions/reverse-proxy-from-droplet-to-app-platform

One other option here would be to just setup a redirect for domain.com/app) to go to a app.domain.com subdomain. That way you will not have to setup a proxy service to handle all requests, but you can just point the blog subdomain A record to the Droplet and then keep the main domain pointed to the App Platform.

Regards

Try DigitalOcean for free

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

Sign up

Featured on Community

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