docker run 命令结束于: nginx: [emerg] 未知指令“events” in /etc/nginx/nginx.conf:1

use*_*045 2 containers config nginx server-sent-events docker

我已在桌面 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;
        }
     }
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

我的构建命令成功了。

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

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

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

小智 10

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

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