1

Today I recur to your expertise I’m a novice with some trouble that is killing my head.

I'm working with a TileServerGL server providing OpenStreet.org map in a docker container within a swarm. This server is working fine, if port 80 is exposed and redirected to, lets say 8080, I can reach its content at [IP Docker Swarm]:8080.

Now I need to add a reverse proxy in front of this container to add some security (but not yet, first I need to make the reverse proxy to work), so I add a Nginx container to the docker-compose.yml file and I’m trying to configure correctly the simplier version of a nginx reverse proxy, without much success.

I have tried:

  • Running it locally with docker-compose up –build
  • Running inside a swarm in my local machine with: docker stack deploy -c docker-compose.yml lab
  • Running inside Vbox machines with: docker stack deploy -c docker-compose.yml lab

The domain resolution is working fine:

  • my swam IP is: 192.168.1.105
  • at etc/hosts I have: 192.168.1.105 app.io

When I open http://app.io at the browser I get the default Nginx welcome page. So far so good. But when I hit http://maps.app.io I still getting the same default welcome page.

The Nginx server log:

10.255.0.2 - - [01/Dec/2018:00:55:59 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36" "-"

I would not appeal to your help with out before reading every post, article , tutorial that I’ve found on the internet. As I see it the “nginx.conf” file is correct, but the reality show me that I’m undoubtedly wrong and blind to my mistake. I’ll really appreciate your help.

I’m running:

  • linux Mint 19 Tara
  • Docker version: Docker version 18.09.0, build 4d60db4
  • Docker machine version: docker-machine version 0.16.0, build 702c267f

The docker-compose.yml file:

version: "3.5"

networks:
  nginx-net:
    driver: overlay

services:
  maps:
    image: xxxx/xxxx:mapstiles
    volumes:
      - ./server_mapstiles/app/data:/data
    networks:
      - nginx-net
    deploy:
      restart_policy:
        condition: on-failure
      replicas: 1

  nginx:
    image: nginx:1.15.7
    container_name: nginx
    ports:
      - "80:80"
    networks:
      - nginx-net
    volumes:
     - ./server_nginx/nginx.conf:/etc/nginx/proxy.conf:ro
    deploy:
      restart_policy:
        condition: on-failure
      replicas: 1
    depends_on:
     - maps

The nginx conf file is:

server {
        listen          80;
        server_name     maps.app.io;

        location / {
                proxy_pass  http://:maps:80;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For 
                $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
                resolver        127.0.0.11;
        }
}

1 Answer 1

1

You have some nasty invalid syntax there for your proxy_pass directive.

proxy_pass http://:maps:80; isn't a valid proxy pass destination, as http://:maps:80 will fail because of that first colon after the //.

Try proxy_pass http://maps:80; but keep in mind the NGINX configuration pitfall of using a hostname to define a location/proxy pass destination/etc.

Sign up to request clarification or add additional context in comments.

4 Comments

Thomas, thanks for your help. I guess when one stare too much, one stop seeing. About the NGINX configuration pitfall that you name, a doubt assault me. Working with Docker I understand that the Docker daemon acts as a DCHP server and name resolution is performed based on the container name. The internal IP could change depending the Docker Machine or when restarted. In this case how should this be configured? 1)Look up the container IP and pass it to the NGINX configuration file, as suggested for the documentation or 2) shall I still using the containers name, relaying in Docker?
The link is dead. looks like nowadays many widely used software are trying to troubling people from using their free version by means like removing good documentation or moving documentation to somewhere harder to find.
I managed to find the link github.com/nginxinc/nginx-wiki/blob/master/source/start/topics/… the wiki is offline and is only archived on github.
@RnMss you could propose an edit to my post next time to update the link location. Updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.