首页 > 解决方案 > nginx:在 /etc/nginx/nginx.conf:44 的上游“tellform”中找不到 [emerg] 主机

问题描述

我正在尝试在 docker 中运行的 Ubuntu 16.04 上设置 TellForm。

我已经根据文档设置了所有内容,但是当我运行它时,我收到以下错误,最终关闭了一个容器:

nginx:在 /etc/nginx/nginx.conf:44 的上游“tellform”中找不到 [emerg] 主机

这是我的 Nginx.conf:

    #  Basic configuration
user nginx;
worker_processes  1;
error_log /dev/stderr info;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    # Standard HTTP configuration with slight hardening
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log /dev/stdout;
    sendfile on;
    keepalive_timeout  65;
    server_tokens off;

    #Websockets Server
    server {

      {% if NODE_ENV == "development" %}
        listen {{SOCKET_PORT}};
      {% else %}
        listen 80;
        listen [::]:80;
        server_name {{ SOCKETS_URL }};

        # Only enable HTTPS if TLS is enabled with no error
        {% if TLS and not TLS_ERROR %}
          listen 443 ssl;
        {% if TLS and not TLS_ERROR %}
          listen 443 ssl;
          listen [::]:443 ssl;

          include /etc/nginx/tls.conf;
          add_header Strict-Transport-Security max-age=15768000;

          if ($scheme = http) {
            return 301 https://$host$request_uri;
          }
        {% endif %}

      {% endif %}

      location / {
        proxy_pass http://tellform:20523;
        proxy_read_timeout 90;

        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-Proto $scheme;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        {% if TLS and not TLS_ERROR %}
          proxy_set_header X-Forwarded-Proto https;
        {% endif %}
      }
        {% endif %}
      }

      {% if TLS_FLAVOR == 'letsencrypt' %}
      location ^~ /.well-known/acme-challenge/ {
          proxy_pass http://127.0.0.1:8008;
      }
      {% endif %}
    }

    server {
      #Add server_name for per-user subdomains
      {% if SUBDOMAINS_DISABLED == "FALSE" %}
        server_name {{BASE_URL}} {{SUBDOMAIN_URL}};
      {% else %}
        server_name {{BASE_URL}};
      {% endif %}

      listen 80;
      listen [::]:80;

      # Only enable HTTPS if TLS is enabled with no error
      {% if TLS and not TLS_ERROR %}
        listen 443 ssl;
        listen [::]:443 ssl;

        include /etc/nginx/tls.conf;
        add_header Strict-Transport-Security max-age=15768000;

        if ($scheme = http) {
          return 301 https://$host$request_uri;
        }
          return 301 https://$host$request_uri;
        }
      {% endif %}

      root /usr/share/nginx/html;
      index index.html index.htm;

      location / {
        proxy_pass http://tellform:5000;
        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 ;

        {% if TLS and not TLS_ERROR %}
          proxy_set_header X-Forwarded-Proto https;
        {% endif %}
      }

      {% if TLS_FLAVOR == 'letsencrypt' %}
      location ^~ /.well-known/acme-challenge/ {
          proxy_pass http://127.0.0.1:8008;
      }
      {% endif %}
    }
}

这是 .env(TellForm 的配置:

# Mailu main configuration file
#
# Most configuration variables can be modified through the Web interface,
# these few settings must however be configured before starting the mail
# server and require a restart upon change.

###################################
# Common configuration variables
###################################

# Set this to the path where Mailu data and configuration is stored
# Mac users: Change to a Docker accessible folder
ROOT=/opt/tellform_data

# Set to what environment you will be running TellForm in (production or development)
NODE_ENV=production

# Set to a randomly generated 16 bytes string
SECRET_KEY=ChangeMeChangeMe

# URI of Mongo database that TellForm will connect to 
#DO NOT CHANGE
MONGODB_URI=mongodb://mongo/tellform

# URL Redis server that TellForm will connect to
#DO NOT CHANGE
REDIS_URL=redis://redis:6379

# Port that the TellForm Node app will listen on
PORT=5000

# Domain that TellForm's admin panel will be hosted at
BASE_URL=159.65.251.176

# Port that SocketIO server (for analytics) will listen on
SOCKET_PORT=20523

#Choose what kind of TLS you want
TLS_FLAVOR=cert

###################################
# Optional features
###################################

# Set this to enable coveralls.io support
COVERALLS_REPO_TOKEN=NC5TbhEeeJXqos552EHyRORvuVtTChTWq

# Disable signups for your TellForm instance
SIGNUP_DISABLED=FALSE

# Disable per-user custom subdomains
SUBDOMAINS_DISABLED=FALSE

# Url that subdomains will be hosted at (has to have domain name as ADMIN_URL)
# Only used when SUBDOMAINS_DISABLED=FALSE
SUBDOMAIN_URL=*.tellform.dev

# Enable running TellForm in pm2's 'cluster' mode
ENABLE_CLUSTER_MODE=FALSE
###################################
# Mail settings
###################################

# Set this to set the username credential of your SMTP service
MAILER_EMAIL_ID=

# Set this to set the password credential of your SMTP service
MAILER_PASSWORD=

# Set this to set the email address that all email should be sent from for signup/verification emails
MAILER_FROM=

# Set this to any services from https://nodemailer.com/smtp/well-known/ to use a 'well-known' email provider
MAILER_SERVICE_PROVIDER=

# Set these if you are not using a 'MAILER_SERVICE_PROVIDER' and want to specify your SMTP server's address and port
MAILER_SMTP_HOST=
MAILER_SMTP_PORT=

# Set this if you are using a custom SMTP server that supports SSL
MAILER_SMTP_SECURE

###################################
# Automatic Admin Creation Settings
###################################

# Set this to "TRUE" if you wish to automatically create an admin user on startup
CREATE_ADMIN=FALSE

# Set this to set the email used by your default admin account
ADMIN_EMAIL=admin@admin.com
# Set this to set the username of your default admin acconut
ADMIN_USERNAME=root

# Set this to set the password of your default admin account
ADMIN_PASSWORD=root

###################################
# Advanced settings
###################################

# Set this to server your websockets server on a seperate URL
SOCKETS_URL=127.0.0.1

# Set this to change the port that TellForm will listen on
PORT=5000

# Set this to your Google Analytics ID to enable tracking with GA
GOOGLE_ANALYTICS_ID=

# Set this to your Sentry.io DSN code to enable front-end JS error tracking with Sentry.io
RAVEN_DSN

# Set this to set the 'name' meta property in the HTML <head>
APP_NAME=

# Set this to set the 'keywords' meta property in the HTML <head>
APP_KEYWORDS=

# Set this to set the 'description' meta property in the HTML head
APP_DESC=

我已经尝试了几乎所有我能想到的东西,但我没有取得任何进展。git repo 开发人员似乎已停止维护或支持该软件包。我希望另一双眼睛可能会有所帮助。

标签: dockernginxdocker-composedockerfile

解决方案


上游没有定义,所以 nginx 不知道请求应该被路由到哪里。根据提供的信息,配置应如下所示:

upstream tellform_ext {
  server 159.65.251.176:20523;
}
upstream tellform_local {
  server 127.0.0.1:5000;
}


  server { 
  {% if NODE_ENV == "development" %}
    listen {{SOCKET_PORT}};
  {% else %}
   .....       

  location / {
    proxy_pass http://tellform_ext;
    proxy_read_timeout 90;
   .....
}
  server {
  #Add server_name for per-user subdomains
  {% if SUBDOMAINS_DISABLED == "FALSE" %}
   .....
location / {
    proxy_pass http://tellform_local; 
    proxy_redirect off;
   .....
}
`

您需要在两个位置进行替换,因为在第二个服务器proxy_pass中会发生错误。


推荐阅读