2

Trying to add varnish to nginx using a docker container name rather than IP address.

I've tried adding it directly set_real_ip_from site-varnish but that doesn't work.

Tried adding an upstream (below) and tried set_real_ip_from varnish_backend with no luck

upstream varnish_backend {
    server site-varnish;
}

Any help would be appreciated. I've added below the current working conf for reference.

upstream fastcgi_backend {
    server site-fpm;
}
server {
    listen 80;
    listen 443 ssl;
    server_name localhost;
    location = /ping {
        set_real_ip_from      192.168.176.2;
        real_ip_header        X-Forwarded-For;

        access_log            off;
        allow                 127.0.0.1;
        deny                  all;


        fastcgi_param         SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include               fastcgi_params;
        fastcgi_pass          fastcgi_backend;
    }
}

docker-compose.yml

version: "2"
services:
  site-varnish:
    build:
      context: ./etc/varnish/
    ports:
      - 80
    networks:
      - frontend

  site-web:
    build:
      context: ./etc/nginx/
    volumes_from:
      - site-appdata
    env_file:
      - ./global.env
    restart: always
    networks:
      - backend
      - frontend

  site-fpm:
    build:
      context: ./etc/7.2-fpm/
    ports:
      - 9000
    volumes_from:
      - site-appdata
    env_file:
      - ./global.env
    networks: 
      - backend

  site-appdata:
    image: tianon/true
    volumes:
      - ./html:/var/www/html

networks:
  frontend:
    external:
      name: webproxy
  backend:
    external:
      name: backbone
6
  • are you using both varnish and nginx in containers? did you using docker-compose for the stack ? Commented Aug 21, 2019 at 5:20
  • yes, varnish and nginx are in separate containers, and using docker-compose for the stack. I've tried referencing them by the service name, site-varnish but its not working. I'm sure I'm making a syntax error somewhere. Commented Aug 21, 2019 at 7:15
  • you should provide the docker-compose in the question Commented Aug 21, 2019 at 7:17
  • added. thanks for providing feedback so I can ask better questions. Commented Aug 22, 2019 at 0:35
  • which nginx version is that ? hostname is enabled from 1.13.1 Commented Aug 22, 2019 at 7:00

1 Answer 1

1

I've updated the nginx version based upon @LinPy suggestion, to > 1.13.1 and am able to use set_real_ip_from site-varnish directly inside my conf.

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

Comments

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.