使用主机名而不是 IP 地址将清漆服务器添加到 nginx

Adding varnish server to nginx using hostname rather than IP address

尝试使用 docker 容器名称而不是 IP 地址将 varnish 添加到 nginx。

我试过直接添加它 set_real_ip_from site-varnish 但那不起作用。

尝试添加上游(下图)并尝试 set_real_ip_from varnish_backend 但没有成功

upstream varnish_backend {
    server site-varnish;
}

如有任何帮助,我们将不胜感激。我已经在当前工作的 conf 下面添加以供参考。

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

我已经根据@LinPy 的建议将 nginx 版本更新到 > 1.13.1,并且能够直接在我的 conf 中使用 set_real_ip_from site-varnish