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

时间:2020-04-30 20:21:41

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

我已经从Windows 10 OS的Ubuntu bash shell中安装了nginx-extras。需要启动docker容器以使用ASP.NET Core 3.1 Blazor Web程序集应用程序来提供静态网页。我的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中的未知指令“事件” nginx:/etc/nginx/nginx.conf:1中的[emerg]未知指令“事件”

我对Nginx和容器化技术还很陌生,因此我们将不胜感激任何帮助。谢谢。

2 个答案:

答案 0 :(得分:0)

我通过排除自定义nginx.conf文件以通过从dockerfile中删除最后一行来覆盖默认nginx.conf文件来解决此问题。现在我的dockerfile看起来像这样: 从mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR / app 复制。 ./ RUN dotnet发布-c释放-o输出

从FROM Nginx WORKDIR / usr / share / nginx / html COPY --from = build-env / app / output / wwwroot /。

答案 1 :(得分:0)

我遇到了同样的问题并通过删除“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;
    }
}
}