Nginx Reverse Proxy not redirecting?


I’m trying to setup docker-compose with nginx as a reverse proxy targeting gogs.

If I enter the ip address of the reverse proxy in the address bar, it redirects to gogs and but the ip address is still in the address bar. If I use a host name configured in /etc/hosts then I just get the Nginx welcome page. I’ve have the full details here:

Anyone know if this has something to do with Gogs setup? I’ve filed an issue with the Nginx docker repository here:


Of course… what else do you expect?

Looks like you didn’t config NGINX correctly (or even not at all…)


The configuration works when I’m not running it with docker compose. I filed in issue with them as well. I think the case maybe be that with the proxy configuration has to have the host name set with with an upstream declaration as is done in this article. I’ll be testing it out soon.

Of course… what else do you expect?

Well I worded that one a bit “Captain obviously’ish”, but the point I was making is that the proxy redirect does work in that case. In other words the nginx ip address is and the gogs address is so the redirect is working, and we see in the address bar.

Now all I want to do is set in my /etc/hosts to so that I can enter in the address bar, and have the redirect work still, but this does not work. In other words when I use a host name that should matches the IP address that nginx does perform the redirect from, then nginx ignores the redirect.

So it should work … but it does not.

One thing I wanted to make sure of is that Gogs does have have any “special” programming where it would ignore requests under certain conditions right? In other words this has to be an nginx or a docker compose issue?


Generally, you can only do one way or other:

  1. Do not touch /etc/hosts but setup NGINX to redirect to Besides, your DNS must know should be resolved to which is your NGINX IP.
  2. Set your hostname with Gogs IP (in your case and no NGINX involved.

However, if you see welcome page from NGINX, from what I know the domain name you expect is not matched with any proxy config so NGINX serves as a static website and display default HTML. Otherwise, you should see working Gogs page or 502.


Gogs does not care where the request comes from, as long as it could reach the Gogs, Gogs processes it.