宿主机ip

如果不正确设置proxy_pass的ip地址,可能会出现找不到的情况,浏览器端得到的结果是502
查看宿主机ip地址

  1. log ip addr show docker0
  2. 4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  3. link/ether 02:42:f7:19:f7:88 brd ff:ff:ff:ff:ff:ff
  4. inet 172.17.0.1/16 scope global docker0
  5. valid_lft forever preferred_lft forever

nginx配置

  1. location /apps/ {
  2. proxy_set_header Host $host;
  3. proxy_set_header X-Real-IP $remote_addr;
  4. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  5. proxy_set_header Cookie $http_cookie;
  6. proxy_pass http://172.17.0.1:4000/;
  7. proxy_redirect default;
  8. proxy_buffer_size 64k;
  9. proxy_buffers 32 32k;
  10. proxy_busy_buffers_size 128k;
  11. }