Nginx Reverse Proxy not redirecting?


#1

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:


#2

Of course… what else do you expect?

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


#3

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 203.0.113.2 and the gogs address is 203.0.113.1 so the redirect is working, and we see 203.0.113.2 in the address bar.

Now all I want to do is set git.example.com in my /etc/hosts to 203.0.113.2 so that I can enter git.example.com 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?


#4

Generally, you can only do one way or other:

  1. Do not touch /etc/hosts but setup NGINX to redirect git.example.com to 203.0.113.1. Besides, your DNS must know git.example.com should be resolved to 203.0.113.2 which is your NGINX IP.
  2. Set your hostname with Gogs IP (in your case 203.0.113.1) 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.


#5

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