nginx 未知指令“上游”

发布于 2024-12-11 11:26:31 字数 1444 浏览 0 评论 0原文

我使用 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

I'm using nginx as a proxy server to forward requests onto my gunicorn server. When I run sudo nginx -t -c /etc/nginx/sites-enabled/mysite I get the following error.

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

Any idea how to fix it? This is my nginx config:

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;
    }
}

I'm running Ubuntu 10.04 and my nginx version is 0.7.65 which I installed from apt.

This is the output when I run 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囍笑 2024-12-18 11:26:31

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

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

您需要使用 -c /etc/nginx/nginx.conf 或制作一个像上面的块一样的小包装器,然后 nginx -c it。

When you tell nginx to load that file directly, it starts at the global context. The upstream directive is only valid in the http context. When that file is included normally by nginx.conf, it is included already inside the http context:

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

You either need to use -c /etc/nginx/nginx.conf or make a small wrapper like the above block and nginx -c it.

过期以后 2024-12-18 11:26:31

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

nginx: [emerg] "upstream"directive is not allowed in /etc/nginx/nginx.conf

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

events {
工人连接1024;
在这些修复之后,它

工作得很好,这是我的第一次努力,所以我正在猜测我的方法。

I am using nginx version: nginx/1.4.1 on EC2 Ubuntu. I was getting this error:

nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/nginx.conf

To get my instance running I had to wrap the upstream and server sections in an http { } section. It then complained about missing event section. So I added that as follows:

events {
worker_connections 1024;
}

It worked fine after those fixes, this is my first effort so I was guessing my way through.

小情绪 2024-12-18 11:26:31

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

Turns my nginx config was ok. The problem was with my gunicorn server was not running properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文