【问题标题】:Nginx on OSX: "server" directive is not allowed hereOSX 上的 Nginx:此处不允许使用“服务器”指令
【发布时间】:2016-02-20 14:27:03
【问题描述】:

我正在尝试在我的 Mac 上通过 Nginx 为 Node 应用程序提供服务,但遇到了问题。

在 Ubuntu 上,我总是把配置文件改成这个

server {
        listen 80;

        server_name example.com;

        location / {
                proxy_pass http://127.0.0.1:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

但是当我在我的 Mac 上执行相同操作时,我在运行服务器时收到此错误:

nginx: [emerg] "server" 指令在此处不允许 /usr/local/etc/nginx/nginx.conf:1

任何关于为什么会发生这种情况的建议将不胜感激。

【问题讨论】:

  • 您编辑了什么文件,它是如何包含在您的nginx.conf 文件中的?
  • 这是完整的 nginx.conf 吗?在我的 nginx.conf 上,它前面有一个 http-block。
  • @DaveWood 我已经配置了 /usr/local/etc/nginx/nginx.conf。
  • @kometen 是的,这是完整的 conf 文件,这是我在我的 ubuntu 服务器上使用的。
  • @martin 好的。然后我将取消删除我的答案。我有点不放心。 :-)

标签: macos nginx


【解决方案1】:

根据nginx的pagehttp是外块。所以应该在 server 块之前添加一个 http 块。

【讨论】:

    【解决方案2】:

    通过这样做我得到host not found in "$PORT" of the "listen" directive

    http {
        server {
        listen $PORT;
        server_name test-rpc.test.com;
        location / {
            proxy_ssl_server_name on;
            proxy_pass http://test-rpc;
        }
        }
    
        upstream test-rpc {
            server localhost:2000 max_fails=3 fail_timeout=10s;
            server localhost:2001 max_fails=3 fail_timeout=10s;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-08
      • 1970-01-01
      • 2019-03-16
      • 2015-01-08
      • 1970-01-01
      • 2015-06-29
      • 2013-12-07
      • 2021-08-06
      相关资源
      最近更新 更多