docker run命令最终出现在/etc/nginx/nginx.conf:1中的:nginx:[emerg]未知指令



我已经在我的桌面Windows 10 O.S中安装了来自Ubuntu bash shell的nginx extra。这是为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:/etc/nginx/nginx.conf:1中的未知指令"事件">

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

我也有同样的错误。通过更改nginx.conf文件的编码进行了修复。如果你在visualstudio中创建nginx.conf文件(Add->new file(,很可能你会得到错误的编码(其他人也会得到同样的错误(。

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

我通过从dockerfile中删除最后一行,排除了要复制到默认nginx.conf文件上的自定义nginx.conf文件,从而解决了这个问题。现在我的dockerfile是这样的:来自mcr.microsoft.com/dotnet/core/sdk:3.1AS构建环境WORKDIR/app复制/RUN dotnet发布-c发布-o输出

来自nginxWORKDIR/usr/share/nginx/htmlCOPY--from=build env/app/output/wwwwroot/。

我也遇到了同样的问题,并通过删除";事件";以及";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;
}
}
}

最新更新