首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx未知指令"upstream“

nginx未知指令"upstream“
EN

Stack Overflow用户
提问于 2011-10-21 04:07:31
回答 3查看 34.2K关注 0票数 24

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

代码语言:javascript
复制
[emerg]: unknown directive "upstream" in /etc/nginx/sites-enabled/mysite:1
configuration file /etc/nginx/sites-enabled/mysite test failed

你知道怎么修复它吗?这是我的nginx配置:

代码语言:javascript
复制
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时的输出

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-09-24 21:39:10

我的nginx配置是正常的。问题出在我的gunicorn服务器没有正常运行。

票数 4
EN

Stack Overflow用户

发布于 2011-10-21 10:39:18

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

代码语言:javascript
复制
events { }
http {
  include /etc/nginx/sites-enabled/*;
}

你要么需要使用-c /etc/ nginx /nginx.conf,要么像上面的代码块一样做一个小的包装器,然后nginx -c它。

票数 26
EN

Stack Overflow用户

发布于 2013-05-16 08:24:23

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

nginx: emerg "upstream“指令在/etc/nginx/nginx.conf中不允许

要让我的实例运行,我必须将上游和服务器部分包装在http {}部分中。然后,它抱怨缺少事件部分。因此,我添加了如下内容:

事件{ worker_connections 1024;}

在这些修复之后,它工作得很好,这是我的第一次努力,所以我猜我的方式通过。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7841612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档