1

I'm trying to run nginx as a reverse proxy for Gogs using Docker. First I setup gogs and I can see a web page for it rendered on:

http://203.0.113.1:3000/

But I want to have NGINX proxy it for me such that I can leave the port (3000) off the URL. The instructions I'm following come from the NGINX section of this tutorial:

https://www.digitalocean.com/community/tutorials/how-to-set-up-gogs-on-ubuntu-14-04

In order to get this working with docker I created a nginx-data volume, and placed the nginx configuration file in that volume naming it gogs. My configuration file looks like this:

server {
    listen 80;
    server_name 203.0.113.2;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
            proxy_pass http://203.0.113.1:3000;
    }
}

And it's located at the root of the nginx-data volume. I start the nginx container like this:

docker run --name docker-nginx -p 80:80 --net mk1net --ip 203.0.113.2 -v nginx-data:/etc/nginx/sites-enabled/ -d nginx

Now when I visit 203.0.113.2 I'm expecting to see the Gogs page, but I'm just getting the "Welcome to NGINX" page.

Thoughts?

TIA,

Ole

0

Answer:

Place the proxy configuration in a file named gogs.conf within the docker volume and map it like this:

docker run --name docker-nginx -p 80:80 --net mk1net --ip 203.0.113.2 -v nginx-data:/etc/nginx/conf.d/ -d nginx

Explanation:

To see how nginx is configured on a default Ubuntu install I installed it sudo apt-get install nginx and took a look at the configuration file /etc/nginx/nginx.conf. It includes these two lines at the bottom of the configuration:

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

So I compared that to the nginx configuration of the docker container:

docker run --rm -it nginx /bin/ash
root@9475f1693539: cat /etc/nginx/nginx.conf

This configuration only has this line:

include /etc/nginx/conf.d/*.conf;

Hence the configuration from /etc/nginx/sites-enabled/ is not included.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.