【问题标题】:nginx: configuration file /etc/nginx/nginx.conf test failed (host not found in upstream)nginx:配置文件 /etc/nginx/nginx.conf 测试失败(在上游找不到主机)
【发布时间】:2017-08-09 23:23:31
【问题描述】:

我有一个 vagrant box,它已经工作了一段时间,今天由于某种原因,当我尝试重新启动 nginx 时,我得到以下信息。

nginx: [emerg] host not found in upstream "www.myclass.com.192.168.33.10.xip.io" in /etc/nginx/conf.d/myclass.com.conf:19
nginx: configuration file /etc/nginx/nginx.conf test failed

据我所知,我自己没有改变任何东西(除非 Windows 更新做了一些奇怪的事情)

任何人都可以建议如何让 nginx 再次工作并允许我重新启动 nginx 服务 - 看来我无法 ping 主机...任何想法为什么?

这是我的 nginx 配置文件: nginx conf file

--更新-- 运行以下命令检查端口 80 上的内容。(阅读了另一篇类似的帖子),我可以看到清漆守护进程位于端口 80 上。这是问题的原因吗?任何建议都会受到欢迎,因为我是新手

sudo netstat -tlnp | grep 80

我的 myclass.com.conf 文件

server {
listen              80;
server_name         class.com.* www.class.com.*;

root /vagrant/www.class.com/public_html;
index index.php;

access_log /vagrant/log/class.com.access.log;
error_log  /vagrant/log/class.com.error.log error;

charset utf-8;

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_page 404 /index.php;

location /socket.io {
    proxy_pass http://www.class.com.192.168.33.10.xip.io:8055;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
}

location / {
    try_files       $uri $uri/ @handler;
    expires         30d;
}

location  /. {
    return 404;
}

location @handler {
    rewrite / /index.php last;
}

location ~ .php/ {
    rewrite ^(.*.php)/ $1 last;
}

location ~ \.php$ {
    try_files                       $uri =404;

    expires                         off;

    fastcgi_read_timeout            900;
    fastcgi_index                   index.php;
    fastcgi_pass                    127.0.0.1:9000;
    fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param                   CLASS_ENVIRONMENT LYLE;
    include                         /etc/nginx/fastcgi_params;
}

gzip            on;
gzip_min_length 1000;
gzip_proxied    any;
gzip_types      text/plain application/xml text/css text/js application/x-javascript;

sendfile        off;

}

【问题讨论】:

  • 您需要发布/etc/nginx/conf.d/myclass.com.conf(/etc/nginx/conf.d 中的任何其他内容也会有所帮助。
  • 感谢您的评论 - 我现在已将其添加到上面

标签: nginx vagrant


【解决方案1】:

你只需要放置可以解析此类域名的解析器:

resolver                  8.8.8.8 valid=300s;
resolver_timeout          10s;

Google DNS (8.8.8.8) 可以解析,但解析为属于网络类 C 的内部地址。

$ dig @8.8.8.8 www.class.com.192.168.33.10.xip.io
;; ANSWER SECTION:
www.class.com.192.168.33.10.xip.io. 299 IN A    192.168.33.10

【讨论】:

  • 但是为什么这会阻止 nginx 正常启动呢?
  • 我在配置中没有看到default resolver server。如果您在 proxy_pass 中使用 FQDN,则需要一个。
  • @Phil 我希望有一天有人能够回答你的问题。就我而言,该服务不再存在,但我仍然想启动 nginx。很烂不是吗?
【解决方案2】:

您的问题来自这一行:

proxy_pass http://www.class.com.192.168.33.10.xip.io:8055;

服务器很可能难以解析该 DNS 名称。你可能还想看看https://serverfault.com/questions/341810/nginx-failing-to-resolve-upstream-names-on-reload-even-if-they-do-resolve-by-the

【讨论】:

    【解决方案3】:

    可能有点晚了,但有一个简单的解决方案。改变

    www.class.com.192.168.33.10.xip.io
    

    进入

    www.class.com.192.168.33.10.nip.io
    

    它应该可以在任何 DNS 上解析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-22
      • 2021-02-15
      • 2021-10-01
      • 1970-01-01
      • 2014-04-13
      • 2020-11-08
      • 2021-06-14
      • 2017-04-01
      相关资源
      最近更新 更多