Nginx: 확인되지 않은 호스트 이름(HTTPS)

Nginx: 확인되지 않은 호스트 이름(HTTPS)

API에 대한 최소 nginx 구성을 설정하려고 하는데 SSL/HTTPS가 작동하지 않습니다.

간단히 말해서 /healthcheck엔드포인트는 의도한 대로 작동하지만 다른 것은 작동하지 않습니다.


nginx와 함께 GCE 인스턴스의 Docker 컨테이너에서 실행되는 API 애플리케이션이 있습니다.

           Internet
               +
               |
               |
               v
+--------------+----------------+
|             GCP               |
|                               |
|    +--------------------+     |
|    |Google Load Balancer|     |
|    +---------+----------+     |
|              |                |
|              |                |
|              |                |
|              v                |
|   +----------+------------+   |
|   | Google Compute Engine |   |
|   |                       |   |
|   | +-------------------+ |   |
|   | |  Server instance  | |   |
|   | |                   | |   |
|   | | +------+  +-----+ | |   |
|   | | |Docker|  |nginx| | |   |
|   | | |      |  +-----+ | |   |
|   | | | API  |          | |   |
|   | | +------+          | |   |
|   | +-------------------+ |   |
|   +-----------------------+   |
|  ---------------------------  |
+-------------------------------+

모든 HTTP 트래픽은 로드 밸런서를 통과하고 nginx에 도달합니다. 엔드포인트가 /healthcheckAPI( 를 반환함 200 OK)로 직접 이동하는 반면, 다른 모든 항목은 로드 밸런서를 통해 HTTPS로 다시 라우팅되어야 합니다.

모든 HTTPS 트래픽은 API로 바로 이동해야 합니다.

server내 구성에는 두 개의 블록이 있습니다 .
첫 번째 블록:

server {
    listen 80;
    server_name  my-domain.com;

    location /healthcheck {
        proxy_pass http://API_IP:8080/healthcheck;
    }

    location / {
        return 301 https://$server_name$request_uri;
    }
}

두 번째 블록:

server {
    listen 443 ssl;
    server_name my-domain.com;

    location / {
        proxy_pass http://API_IP:8080$request_uri;
    }
}

와 더불어불면증 REST 클라이언트: HTTP 또는 HTTPS를
누르면 /healthcheck작동하지만 오류 메시지만 표시 /users됩니다 . 상태 코드는 없고 이 오류 메시지만 있습니다./reviewsError: Couldn't resolve host name


모든 도움을 주시면 대단히 감사하겠습니다.


업데이트

출력wget -S my-domain.com/users
(실제 도메인 및 IP가 변경됨)

$ wget -S my-domain.com/users
--2018-08-30 14:09:08--  http://my-domain.com/users
Resolving my-domain.com (my-domain.com)... *IP REDACTED*
Connecting to my-domain.com (my-domain.com)|*IP REDACTED*|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 301 Moved Permanently
  Server: nginx/1.10.3 (Ubuntu)
  Date: Thu, 30 Aug 2018 12:09:09 GMT
  Content-Type: text/html
  Content-Length: 194
  Location: https://my-domain.com/users
  Via: 1.1 google
Location: https://my-domain.com/users [following]
--2018-08-30 14:09:09--  https://my-domain.com/users
Resolving my-domain.com (my-domain.com)... failed: Name or service not known.
wget: unable to resolve host address ‘dev.api.godlypatruljen.no’

답변1

오른쪽.

나는 동료로부터 올바른 길로 가는 데 도움이 되는 조언을 얻었습니다. 가장 좋은 해결책은 아닐 수도 있지만 효과가 있습니다.

나는 두 개의 오래된 server블록을 모두 교체했습니다.하나새로운:

server {
    listen 80;
    listen [::]:80;
    server_name my-domain.com;

    set $redirect_to_https 0;

    if ($http_x_forwarded_proto != 'https') {
        set $redirect_to_https 1;
    }

    if ($request_uri = '/healthcheck') {
        set $redirect_to_https 0;
    }

    if ($redirect_to_https = 1) {
        return 301 https://$host$request_uri;
    }

    location / {
        proxy_pass http://$api_ip:$api_port;
    }
}

처리해야 하는 일부 극단적인 경우(서버의 정적 위치, 컨테이너 내부가 아닌 등)로 인해 (여기에 표시된 것 외에) 몇 가지 추가 locations 및 s도 있지만 이 예에서는 설명해야 합니다. if해결책은 아주 좋습니다.

관련 정보