简体   繁体   English

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

[英]docker run command ends up in : nginx: [emerg] unknown directive “events” in /etc/nginx/nginx.conf:1

I have installed nginx-extras from Ubuntu bash shell in my desktop Windows 10 OS The is required to spin up a docker container for an ASP.NET Core 3.1 Blazor web assembly application for serving the static web pages. I have installed nginx-extras from Ubuntu bash shell in my desktop Windows 10 OS The is required to spin up a docker container for an ASP.NET Core 3.1 Blazor web assembly application for serving the static web pages. My nginx.conf:我的 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: 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

My build command was successful.我的构建命令成功。

However when I wanted to create a container using the command: docker run -p 8080:80 docker-wasm-blazor It gave me an error:但是,当我想使用以下命令创建容器时: docker run -p 8080:80 docker-wasm-blazor 它给了我一个错误:

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

I am very new to nginx and containerisation , so any help will be highly appreciated.我对 nginx 和 containerisation 非常陌生,因此我们将不胜感激。 Thanks.谢谢。

I sorted out the issue by excluding the custom nginx.conf file to copy over the default nginx.conf file by removing the last line from the dockerfile.我排除了自定义 nginx.conf 文件以通过从 dockerfile 中删除最后一行来复制默认 nginx.conf 文件,从而解决了这个问题。 Now my dockerfile looks like this: FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app COPY.现在我的 dockerfile 看起来像这样:FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app COPY。 ./ RUN dotnet publish -c Release -o output ./ 运行 dotnet 发布 -c 发布 -o output

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

I got the same issue and fixed it by removing the white spaces from before and after "events" and "http", so my config file become:我遇到了同样的问题并通过删除“事件”和“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;
    }
}
}

I had the same error.我有同样的错误。 Fixed by changing the encoding of the nginx.conf file.通过更改 nginx.conf 文件的编码进行修复。 If you create the nginx.conf file in/with visual studio (Add -> new File) it's most likely that your will get the wrong encoding (other people got the same error).如果您在 Visual Studio 中/使用 Visual Studio 创建 nginx.conf 文件(添加 -> 新文件),您很可能会得到错误的编码(其他人也有同样的错误)。

In my case the encoding was UTF-8 and I needed us-ascii encoding.在我的情况下,编码是 UTF-8 ,我需要 us-ascii 编码。 The easiest was to delete my nginx.conf file and recreate it outside of visual studio (I used Sublime text but I think you can use notepad).最简单的方法是删除我的 nginx.conf 文件并在 Visual Studio 之外重新创建它(我使用了 Sublime 文本,但我认为您可以使用记事本)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 - nginx: [emerg] "server" 指令在 /etc/nginx/nginx.conf:1 中是不允许的 - Error - nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1 docker vs docker-compose nginx:[emerg] host在/etc/nginx/nginx.conf:21的上游“httpstat.us”中找不到 - docker vs docker-compose nginx: [emerg] host not found in upstream “httpstat.us” in /etc/nginx/nginx.conf:21 nginx:在 /etc/nginx/conf.d/nginx.conf:12 的上游“php”中找不到 [emerg] 主机 - nginx: [emerg] host not found in upstream "php" in /etc/nginx/conf.d/nginx.conf:12 nginx:在/etc/nginx/nginx.conf:44的上游“ tellform”中找不到[emerg]主机 - nginx: [emerg] host not found in upstream “tellform” in /etc/nginx/nginx.conf:44 emerg 1#1:在 /etc/nginx/nginx.conf:6 的上游“dashboard-fe:3000”中找不到主机 - emerg 1#1: host not found in upstream “dashboard-fe:3000” in /etc/nginx/nginx.conf:6 nginx: [emerg] "http" 指令在 /etc/nginx/conf.d/default.conf:1 中是不允许的 - nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 nginx: [emerg] "http" 指令在 /etc/nginx/conf.d/site.conf:1 中是不允许的 - nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/site.conf:1 nginx 容器:未知指令“事件”,.conf 错误 - nginx container: unknown directive "events", .conf error nginx: [emerg] “server”指令在 /etc/nginx/conf.d 中是不允许的,即使服务器标签在 http 中 - nginx: [emerg] “server” directive is not allowed here in /etc/nginx/conf.d even if server tag is inside http 运行独立 docker 容器时,在 /etc/nginx/conf.d/nginx.conf 上游中找不到主机 - host not found in upstream in /etc/nginx/conf.d/nginx.conf when running standalone docker containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM