내가 원하는 무엇
에서 "잃어버린 연결"메시지가 https://github.com/jwilder/nginx-proxy 패키지가있다. 이것은 "HTTP"에 매우 유용하지만 TCP에도 사용하고 싶습니다. 당신이 볼 수 있듯이, 내가 nginx.conf
에 stream {}
블록을 추가 한 https://github.com/fchris82/nginx-proxy/commit/33d80ea4d4be5d511e4dab0413d516770aa15262도커 프록시 : 호스트 컴퓨터
과 /etc/nginx/stream.conf.d
디렉토리 (MySQL은) 다음
내 변화입니다. 여기에 스트림 블록 default.conf
생성됩니다 : 당신이 오류를 재현 할 수있는 방법 내가 무슨 짓을
access_log off;
error_log /var/log/nginx/debug.log debug;
resolver 127.0.0.11;
# whoami.loc
upstream whoami.loc {
## Can be connect with "nginxproxy_default" network
# nginxproxy_mysql_1
server 192.168.32.2:3306;
}
server {
listen whoami.loc:81;
proxy_pass whoami.loc;
}
,
# Set host
> sudo echo "127.0.0.1 whoami.loc" >> /etc/hosts
# Start containers
> docker-compose up -d
# "Login" the proxy container
> docker-compose exec nginx-proxy /bin/bash
# Test connect to MySQL from proxy container
root> mysql -u root -proot -h whoami.loc -P 81
# --> OK, it works! Let's exit.
mariadb> \q
# Exit from container
root> exit
# Check host
> ping whoami.loc
# --> OK, 127.0.0.1
# Check docker ports
> docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------
nginxproxy_mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp
nginxproxy_nginx-proxy_1 /app/docker-entrypoint.sh ... Up 0.0.0.0:180->80/tcp, 0.0.0.0:81->81/tcp
nginxproxy_whoami_1 /app/http Up 8000/tcp
# --> OK
# Try to direct connection from host (You can read the IP from the /etc/nginx/stream.conf.d/default.conf file)
> mysql -u root -proot -h 192.168.32.2
# --> OK, exit
mysql> \q
# Try to connect from host with "domain" through docker proxy
> mysql -u root -proot -H whoami.loc -P 81 --protocol=tcp
# ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
그래서, 컨테이너에서 작동하지만 왜 호스트에서 작동하지 않는 이유는 사람의 생각을 갖고 ?
은 "솔루션"
이 내가 정말 원하는 것을위한 솔루션 없습니다. 나는 이와 같은 것을 원했다 : Nginx TCP forwarding based on hostname. Tarun's answer 오류 메시지가 해결되었습니다. 감사합니다.
당신은'server' proxy_pass를하고'stream' proxy_pass를 할 것으로 기대하고 있습니까? –
@ TarunLalwani 무슨 뜻인지 이해가 안됩니다. 포함 된 conf는'stream {}'블록에 있습니다. 다음은'server'-s도 있습니다 : https://www.nginx.com/resources/admin-guide/tcp-load-balancing/. –
Okie 내 잘못, 내가 올바르게 설정을 읽지 않았어, 그것은 스트림 블록의 일부만 보지 못했어요. 'telnet whoami.loc 81'을 시도해 볼 수 있습니까? –