【问题标题】:docker run command ends up in : nginx: [emerg] unknown directive “events” in /etc/nginx/nginx.conf:1docker run 命令结束于: nginx: [emerg] unknown directive “events” in /etc/nginx/nginx.conf:1
【发布时间】:2020-08-15 07:52:24
【问题描述】:

我已经在我的桌面 Windows 10 操作系统中安装了来自 Ubuntu bash shell 的 nginx-extras。需要为 ASP.NET Core 3.1 Blazor Web 程序集应用程序启动 docker 容器以提供静态网页。我的 nginx.conf:

 events { }
   http {
      include mime.types;
      types {
         application/wasm wasm;
       }
     server {
        listen 80;
        index index.html;
        location / {
           root /var/www/web;
           try_files $uri $uri/ /index.html =404;
        }
     }
}

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
COPY . ./
RUN dotnet publish -c Release -o output

FROM nginx:alpine
WORKDIR /var/www/web
COPY --from=build-env /app/output/wwwroot .
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

我的构建命令成功了。

但是当我想使用命令创建容器时: docker run -p 8080:80 docker-wasm-blazor 它给了我一个错误:

[emerg] 1#1:/etc/nginx/nginx.conf:1 中的未知指令“events” nginx:/etc/nginx/nginx.conf:1 中的[emerg] 未知指令“events”

我对 nginx 和容器化非常陌生,因此我们将非常感谢任何帮助。谢谢。

【问题讨论】:

  • 我无法重现您的问题:如果我使用您的 nginx.confnginx:alpine 构建图像,一切似乎都可以正常工作。
  • 您是否像我一样尝试通过 ASP.NET Core 3.1 Blazor Web 程序集进行复制?即便如此,正如我上面所写的,我可以使用 build 命令创建一个图像。但是,当我发出 docker run 命令(以创建图像实例或容器)时,它以错误告终。

标签: docker nginx containers config server-sent-events


【解决方案1】:

我有同样的错误。通过更改 nginx.conf 文件的编码来修复。如果您在 Visual Studio 中/使用 Visual Studio 创建 nginx.conf 文件(添加 -> 新文件),您很可能会得到错误的编码(其他人也有同样的错误)。

在我的情况下,编码是 UTF-8,我需要 us-ascii 编码。最简单的方法是删除我的 nginx.conf 文件并在 Visual Studio 之外重新创建它(我使用了 Sublime 文本,但我认为您可以使用记事本)。

【讨论】:

  • 哦,伙计,你一针见血。我使用 Add -> New Item Class.cs 创建了 conf 文件。然后重命名并编辑它。现在我删除了它,然后从git hub source 得到它。
【解决方案2】:

我通过从 dockerfile 中删除最后一行来排除自定义 nginx.conf 文件以复制默认 nginx.conf 文件,从而解决了这个问题。现在我的 dockerfile 看起来像这样: FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env 工作目录 /app 复制 。 ./ 运行 dotnet publish -c 发布 -o 输出

来自 nginx WORKDIR /usr/share/nginx/html 复制 --from=build-env /app/output/wwwroot/ 。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,并通过删除“events”和“http”前后的空格来修复它,所以我的配置文件变成了:

    events{}
    http{
        include mime.types;
    types {
        application/wasm wasm;
    }
    
    server {
        listen 80;
    
        # Here, we set the location for Nginx to serve the files
        # by looking for index.html
        location / {
            root /usr/local/webapp/nginx/html;
            try_files $uri $uri/ /index.html =404;
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      相关资源
      最近更新 更多