我使用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发布于 2012-09-24 21:39:10
我的nginx配置是正常的。问题出在我的gunicorn服务器没有正常运行。
发布于 2011-10-21 10:39:18
当您告诉nginx直接加载该文件时,它从全局上下文开始。upstream指令仅在http上下文中有效。当该文件被nginx.conf正常包含时,它已经包含在http上下文中:
events { }
http {
include /etc/nginx/sites-enabled/*;
}你要么需要使用-c /etc/ nginx /nginx.conf,要么像上面的代码块一样做一个小的包装器,然后nginx -c它。
发布于 2013-05-16 08:24:23
我在EC2 Ubuntu上使用的是nginx版本: nginx/1.4.1。我得到了这个错误:
nginx: emerg "upstream“指令在/etc/nginx/nginx.conf中不允许
要让我的实例运行,我必须将上游和服务器部分包装在http {}部分中。然后,它抱怨缺少事件部分。因此,我添加了如下内容:
事件{ worker_connections 1024;}
在这些修复之后,它工作得很好,这是我的第一次努力,所以我猜我的方式通过。
https://stackoverflow.com/questions/7841612
复制相似问题