2017-11-29 15 views
0

포트 8080에서 정상적으로 작동하는 Java/Tomcat 앱 앞에 맨 처음 뼈대 nginx 리버스 프록시를 추가하는 행운이 없습니다. 브라우저가 빈 응답을 반환하고 서버에 로깅이나 오류가 표시되지 않습니다. docker nginx 리버스 프록시 오류가 발생하지 않지만 빈 페이로드가 반환 됨

내 nginx를 Dockerfile입니다 :

FROM nginx 
COPY nginx.conf /etc/nginx/nginx.conf 
EXPOSE 10040 
CMD ["nginx"] 

$ docker run -p 10040:8080 --name rproxy --rm we1p2xxxxxxx.xxx.xx.com:11095/myapp-rproxy nginx -T 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test is successful 
# configuration file /etc/nginx/nginx.conf: 
daemon off; 
error_log /dev/stdout info; 
worker_processes 1; 

events { worker_connections 1024; } 

http { 
    access_log /dev/stdout; 
    sendfile on; 

    upstream docker-myapp { 
     server localhost:8080; 
    } 

    server { 
     listen 10040; 

     location/{ 
      proxy_pass   http://docker-myapp; 
      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; 
     } 
    } 

} 

내가 브라우저에서 http://localhost:10040/ 전화 nginx를 -T에서 내 nginx.conf, 내가 다시 아무것도 얻을 - 빈 응답을. 응답 상태도 아닙니다.

$ docker run -p 10040:8080 --name rproxy --rm we1pxxxxxxxx.xxx.xxx.com:11095/myapp-rproxy nginx-debug 
2017/11/29 14:17:06 [notice] 1#1: using the "epoll" event method 
2017/11/29 14:17:06 [notice] 1#1: nginx/1.13.7 
2017/11/29 14:17:06 [notice] 1#1: built by gcc 6.3.0 20170516 (Debian 6.3.0-18) 
2017/11/29 14:17:06 [notice] 1#1: OS: Linux 4.9.49-moby 
2017/11/29 14:17:06 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 
2017/11/29 14:17:06 [notice] 1#1: start worker processes 
2017/11/29 14:17:06 [notice] 1#1: start worker process 7 

I : 나는이의 nginx에서 시작 로그 출력은/dev/표준 출력

로 연결 한 둘 오류없이 액세스 로그 -

것도 하나를 기록되지 않습니다 로깅에서 더 많은 정보를 얻는 방법을 찾으려고 노력하고 있습니다. 예를 들어 포트 번호를 듣고 있습니다. Cygwin netstat은 Dockerfile에 EXPOSE 10040이 있지만 10040 포트에서 수신 대기하는 것을 표시하지 않습니다.

docker ps입니다 :

$ docker ps 
CONTAINER ID  IMAGE           COMMAND     CREATED    STATUS    PORTS          NAMES 
03d17ec349f7  we1pxxxxxxxx.xxx.xxx.com:11095/myapp-rproxy "nginx"     52 seconds ago  Up 51 seconds  80/tcp, 10040/tcp, 0.0.0.0:10040->8080/tcp rproxy 
eaf3ed033908  we1pxxxxxxxx.xxx.xxx.com:11095/myapp   "/bin/sh -c 'java ..." 2 hours ago   Up 2 hours   0.0.0.0:8080->8080/tcp      myapp 

내가 curl를 사용할 때이 일어나는 것이다 : 나는 윈도우 10에 고정 표시기의 17.09.0-CE-win33을 사용하고

$ curl -i http://localhost:8080 
HTTP/1.1 401 
X-Content-Type-Options: nosniff 
X-XSS-Protection: 1; mode=block 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
Pragma: no-cache 
Expires: 0 
X-Frame-Options: DENY 
WWW-Authenticate: Negotiate 
WWW-Authenticate: Basic realm="xx.xx.xx.COM" 
Content-Length: 0 
Date: Wed, 29 Nov 2017 15:57:38 GMT 

$ curl -i http://localhost:10040 
curl: (52) Empty reply from server 
$ 

, Cygwin에서 함께.

희망, 세계?

[UPDATE 2017년 11월 30일] 포트 잡았다

간단한 실수는 그의 대답에 알렉산더 Altshuler 지적 - 나는 10040로 매핑하는 시도하여, 그래서 이미 고정 표시기 컨테이너 내부에 10040에 nginx를 부착 한

    내가 오류를 볼 수
  • : 몇 가지 질문이 발생되는 - 명령 줄 -p 10040:80 매개 변수 (80)는 내 요청을 차단했다? 분명히 말하지만 포트가없는 상태에서 내 컬 요청 시간이 초과 되었어야합니까?

  • docker psPORTS 필드가 80/tcp 인 이유는 무엇입니까?

    $ curl http://localhost:10040 
    
    :이 얻을

  • $ docker ps 
    CONTAINER ID  IMAGE           COMMAND     CREATED    STATUS    PORTS        NAMES 
    b6379d40d0c2  we1pxxxxxxxx.xxx.xxx.com:11095/myapp   "/bin/sh -c 'java ..." 2 minutes ago  Up 2 minutes  0.0.0.0:8080->8080/tcp    myapp 
    d3d5feb9e63f  we1pxxxxxxxx.xxx.xxx.com:11095/myapp-rproxy "nginx"     20 minutes ago  Up 20 minutes  80/tcp, 0.0.0.0:10040->10040/tcp rproxy 
    

하고 curl 일 : 확실히 그 고정 표시기가 -p 10040:10040 그것을 실행하는 지금 (교체 아웃 curl 연결 시간)

  • 을 열려 있지,이 참조

    <html> 
     
    <head><title>502 Bad Gateway</title></head> 
     
    <body bgcolor="white"> 
     
    <center><h1>502 Bad Gateway</h1></center> 
     
    <hr><center>nginx/1.13.7</center> 
     
    </body> 
     
    </html>

    와 nginx를 밖으로 뱉어 :

    2017/11/30 10:07:32 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET/HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "localhost:10040" 
    2017/11/30 10:07:32 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 172.17.0.1, server: , request: "GET/HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "localhost:10040" 
    2017/11/30 10:07:32 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET/HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "localhost:10040" 
    2017/11/30 10:07:32 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 172.17.0.1, server: , request: "GET/HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "localhost:10040" 
    172.17.0.1 - - [30/Nov/2017:10:07:32 +0000] "GET/HTTP/1.1" 502 173 "-" "curl/7.56.1" 
    2017/11/30 10:07:32 [info] 5#5: *1 client 172.17.0.1 closed keepalive connection 
    

    는 분명히 아직 덴마크의 상태에서 썩은 무언가가,하지만 지금은 내가이 일을 정렬 할 수 있습니다 확신 일부 로깅을 얻고있다.

  • 답변

    0

    먼저 솔루션 here 게시 됨 : 사용

    을 사용자 정의 브리지 네트워크 :

    docker network create -d bridge myapp-net

    그리고는 내가 myapp-net에 부착, 컨테이너를 시작 :

    docker run -p 8080:8080 --network=myapp-net --name myapp --rm myregistry:11095/myapp

    docker run -p 10040:443 --network=myapp-net --name rproxy --rm myregistry:11095/myapp-rproxy

    경고 : 아직 이해하지 못하는 이유는 기본 고정 표시기 브리지 네트워크는하지 않습니다 작동에도 불구하고 작동 docker docs

    1

    docker run -p 10040:10040 ... 
    

    업데이트로 시작해야 고정 표시기의 coniatner을 실행하는 명령을

    은 왜 고정 표시기 추신 포트 필드가 80/TCP를 보여주고있다? 확실히 그 (컬 연결 시간이 초과)

    내가 하나의 이유를 상상할 수 열려 있지 - 당신의 nginx가 502 잘못된 게이트웨이로 응답 이유는 분명하다 docker run -p 80 ...

    을 제공했다 :

    사용자가 설정의 nginx를 연결 localhost : 8080이지만, 컨테이너 내에서 백엔드가 외부 호스트에서 실행됩니다.

    여기에 평소 연습

    - 사용자 정의 네트워크 생성 :

    docker network create --driver bridge mynetwork 
    docker run --network=isolated_nw -p 10040:8080 --name rproxy ... 
    docker run --network=isolated_nw --name myapp ... 
    

    의 Nginx를 설정해야 보이는 아래 등 :

    daemon off; 
    error_log /dev/stdout info; 
    worker_processes 1; 
    
    events { worker_connections 1024; } 
    
    http { 
        # use docker embedded DNS server to resolve myapp host name 
        resolver 127.0.0.11; 
    
        access_log /dev/stdout; 
        sendfile on; 
    
        upstream docker-myapp { 
         server myapp:8080; # !!! 
        } 
    
        server { 
         listen 10040; 
    
         location/{ 
          proxy_pass   http://docker-myapp; 
          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; 
         } 
        } 
    
    } 
    
    +0

    안녕하세요 알렉스, 나는'업스트림'을 없애고, 중복 것으로 보입니다. 또한 역방향 프록시에서 수신 대기하는 포트 80 - 여전히 수신 대기 중입니다. 이유를 모르겠다. 명령 행에서 전혀 선언하지 마라. – Adam