Setup Nginx Reverse Proxy for Docker app on Domain Subfolder

Published

I’ve been struggling to get my Nginx Reverse Proxy to work for a Docker app. Similar questions have been asked but haven’t provided the solution for this situation. I’ve spent hours now trying to get this working.

  • I’m trying to self host Plausible which runs in a Docker container at http://localhost:8000
  • Going to http://server-ip:8000/ works fine

I want to set up a Nginx reverse proxy to provide SSL + and set it up on my domain. The tricky part is that I want to serve it from a subfolder instead of the root.

So serving it from https://app.mydomain.com/plausible instead of https://app.mydomain.com/

Current Code:

location /plausible {
        rewrite ^/plausible/?(.*) /$1 break;
        proxy_pass http://localhost:8000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

The Problem

  • app.mydomain.com/plausible/ redirects to app.mydomain.com/login instead of app.mydomain.com/plausible/login.
  • If I manually go to app.mydomain.com/plausible/login I can see the form field but all the styling and scripts are broken. They try to load from app.mydomain.com/stylesheet.css instead of app.mydomain.com/plausible/stylesheet.css

So I believe the Docker app expects to be on the root URL. So Nginx should rewrite the requests to include the subfolder in some way? I just can’t figure out how to do it.

What I’ve tried:

  • Trailing slash, no trailing slash
  • Just proxy_pass
  • All kinds of rewrite variations

Anyone who can help me in the right direction? Thank you in advance

Source: Docker Questions

Published
Categorised as docker, nginx, nginx-reverse-proxy, subdomain Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq