【问题标题】:nginx unknown directive "upstream"nginx 未知指令“上游”
【发布时间】:2011-12-12 02:23:49
【问题描述】:

我使用 nginx 作为代理服务器将请求转发到我的 gunicorn 服务器。当我运行sudo nginx -t -c /etc/nginx/sites-enabled/mysite 时,出现以下错误。

[emerg]: unknown directive "upstream" in /etc/nginx/sites-enabled/mysite:1
configuration file /etc/nginx/sites-enabled/mysite test failed

知道如何解决吗?这是我的 nginx 配置:

upstream gunicorn_mysite {
    server 127.0.0.1:8000 fail_timeout=0;
}

server {
    listen 80;
    server_name example.com;

    access_log /usr/local/django/logs/nginx/mysite_access.log;
    error_log /usr/local/django/logs/nginx/mysite_error.log;

    location / {
        proxy_pass http://gunicorn_mysite;
    }
}

我正在运行 Ubuntu 10.04,我的 nginx 版本是 0.7.65,我是从 apt 安装的。

这是我运行 nginx -V 时的输出

nginx version: nginx/0.7.65
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-mail --with-mail_ssl_module --with-ipv6 --add-module=/build/buildd/nginx-0.7.65/modules/nginx-upstream-fair

【问题讨论】:

  • 这还是我很有用的,也许把它作为答案发布

标签: django ubuntu nginx gunicorn


【解决方案1】:

当您告诉 nginx 直接加载该文件时,它会从全局上下文开始。上游指令仅在 http 上下文中有效。当 nginx.conf 正常包含该文件时,它已经包含在 http 上下文中:

events { }
http {
  include /etc/nginx/sites-enabled/*;
}

你要么需要使用 -c /etc/nginx/nginx.conf 要么像上面的块和 nginx -c 一样制作一个小包装器。

【讨论】:

    【解决方案2】:

    原来我的 nginx 配置没问题。问题是我的 gunicorn 服务器运行不正常。

    【讨论】:

      【解决方案3】:

      我在 EC2 Ubuntu 上使用 nginx 版本:nginx/1.4.1。我收到了这个错误:

      nginx: [emerg] "upstream" 指令在 /etc/nginx/nginx.conf 中是不允许的

      为了让我的实例运行,我必须将上游和服务器部分包装在 http { } 部分中。然后它抱怨缺少事件部分。所以我补充如下:

      事件{ worker_connections 1024; }

      这些修复后它运行良好,这是我的第一次尝试,所以我在猜测我的方式。

      【讨论】:

      • 使用 Nginx/Thin 在 Mac OS X 上为我工作。
      猜你喜欢
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 2017-07-28
      • 2020-04-09
      • 1970-01-01
      • 2020-08-24
      • 1970-01-01
      • 2013-10-12
      相关资源
      最近更新 更多