nginx: [emerg] хост не найден в вышестоящем "server abcd" при настройке nginx в качестве обратного прокси-сервера для микросервисов на основе докера - PullRequest
0 голосов
/ 03 июля 2018

У нас есть группа обслуживаемых микросервисов, которые уже работают на виртуальной машине с частным внутренним IP. Я сконфигурировал Doginised nginx для установки обратного прокси-сервера перед этими микросервисами, но я получаю хост nginx: [emerg], не найденный в вышестоящей ошибке "ms1".

Ниже приведен файл nginx.conf

#user  nobody;
#Defines which Linux system user will own and run the Nginx server

worker_processes  4;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.

#error_log  logs/error.log; #error_log  logs/error.log  notice;
#Specifies the file where server logs.

#pid        logs/nginx.pid;
#nginx will write its master process ID(PID).

events {
    worker_connections  1024;
    # worker_processes and worker_connections allows you to calculate maxclients value:
    # max_clients = worker_processes * worker_connections
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    # If serving locally stored static files, sendfile is essential to speed up the server,
    # But if using as reverse proxy one can deactivate it
    #tcp_nopush     on;
    # works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once.
    #keepalive_timeout  0;
    keepalive_timeout  65;
    # timeout during which a keep-alive client connection will stay open.
    gzip  on;
    # tells the server to use on-the-fly gzip compression.
    server {
        listen       8080;
        server_name your-domain.com www.your-domain.com;
        #root configuration for static files.
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    upstream consumer-portal {
        server consumer-portal:9006;
    }

    upstream download-zip-service {
        server download-zip-service:9012;
    }

    server {
    listen          8080;
    server_name     www.example.com;

        location /consumer-portal/ {
        proxy_pass http://consumer-portal:9006/;
        }

        location /download-zip-service/ {
        proxy_pass http://download-zip-service:9012/;
        }
    }
}

Ниже приводится содержание моего Dockerfile:

FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]

Ниже приведено содержимое файла docker-compose.yml

version: '3'
services:
  nginx:
    restart: always
    build: ./conf/
    volumes:
    - ./mysite.template:/etc/nginx/conf.d/mysite.template
    ports:
    - "8080:8080"
    networks:
      - cloud

networks:
  cloud:
   driver: bridge

Я использую имя сети в качестве облака, поскольку в облачной сети запущены контейнерный потребительский портал и служба загрузки zip.

Я получаю ошибку ниже при запуске команд:

docker-compose build
docker-compose up

nginx_1  | 2018/07/02 20:48:52 [emerg] 1#1: host not found in upstream "consumer-portal:9006" in /etc/nginx/nginx.conf:50
nginx_1  | nginx: [emerg] host not found in upstream "consumer-portal:9006" in /etc/nginx/nginx.conf:50

Любое руководство приветствуется!

Новый файл conf согласно предложению к этому сообщению:

#user  nobody;
#Defines which Linux system user will own and run the Nginx server

worker_processes  4;
#Referes to single threaded process. Generally set to be equal to the number of CPUs or cores.

#error_log  logs/error.log; #error_log  logs/error.log  notice;
#Specifies the file where server logs.

#pid        logs/nginx.pid;
#nginx will write its master process ID(PID).

events {
    worker_connections  1024;
    # worker_processes and worker_connections allows you to calculate maxclients value:
    # max_clients = worker_processes * worker_connections
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    # If serving locally stored static files, sendfile is essential to speed up the server,
    # But if using as reverse proxy one can deactivate it
    #tcp_nopush     on;
    # works opposite to tcp_nodelay. Instead of optimizing delays, it optimizes the amount of data sent at once.
    #keepalive_timeout  0;
    keepalive_timeout  65;
    # timeout during which a keep-alive client connection will stay open.
    gzip  on;
    # tells the server to use on-the-fly gzip compression.
    server {
        listen       8080;
        server_name your-domain.com www.your-domain.com;
        #root configuration for static files.
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    # upstream consumer-portal {
    #     server consumer-portal;
    # }

    # upstream download-zip-service {
    #     server download-zip-service;
    # }

    server {
    listen          8080;
    server_name     www.example.com;

        location /consumer-portal/ {
        proxy_redirect http://consumer-portal:9006;
        }

        location /download-zip-service/ {
        proxy_redirect http://download-zip-service:9012;
        }
    }
}

1 Ответ

0 голосов
/ 03 июля 2018

Если вы хотите указать вышестоящие серверы, используя имена хостов, вам нужно указать распознаватель

...