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.


Ideally I would set the to the gogs ip, but IIUC I then have to use URLs like Can Dockerized Gogs accept incoming connections on port 80 now? I got my setup from a Digital Ocean article a ways back I think…


That’s the entire point of using NGINX in front of Gogs (and any other alike), you can just visit port 80 and let NGINX redirects your request to backend with whatever port is. Then the URL will be very clean without port number.


I’m using /etc/hosts as the DNS and it does resolve the IP correctly, as I always get the nginx container when entering in in the address bar.

This is my docker compose file. I’ve changed the network addresses to use 115 instead of 113 so that don’t run into conflicts with the manual setup I had earlier (Not using docker compose):

    version: '3'
        build: ./proxy
          - "80:80"
        image: gogs/gogs
          - "3000:3000"
          - gogs-data:/data
        external: true
            - subnet:

The build for the proxy nginx container looks like this:

FROM nginx
COPY gogs.conf /etc/nginx/conf.d/gogs.conf

And the gogs.conf nginx proxy configuration looks like this:

    server {
        listen 80;
        proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP
        location / {

So in other words listen on and forward to where gogs in running.

Finally /etc/hosts has this line in it such that the address gets resolved per

So now points to the Nginx proxy.

Now when I docker-compose up it brings up all the containers (Nginx and Gogs):

ole@mki:~/Gogs/.gogs/docker$ docker-compose up
Starting docker_gogs_1       ... done
Starting docker_gogs-nginx_1 ... done

If I visit in the address bar I get the “Welcome to Nginx” screen. The proxy does not trigger. If I visit:

I redirects to:

So Gogs is running fine, however I cannot get the proxy part working correctly.


Try server_name


Tried it. Still only getting the nginx page:

    server {
        listen 80;
        proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP
        location / {

Testing with curl:

    ole@mki:~/Gogs/.gogs/docker$ curl
    <!DOCTYPE html>
    <title>Welcome to nginx!</title>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>

    <p>For online documentation and support please refer to
    <a href=""></a>.<br/>
    Commercial support is available at
    <a href=""></a>.</p>

    <p><em>Thank you for using nginx.</em></p>


Running out of ideas