nginx: [emerg] /etc/nginx/sites-enabled/default:1 中的未知指令“server”

Kik*_*sen 4 nginx asp.net-core

我正在尝试将 Nginx 设置到我的 ASPNET Core WebApi。但我总是遇到错误。

当我尝试检查我的配置时,我得到:

ubuntu@ip-172-26-12-97:~$ sudo nginx -t
nginx: [emerg] unknown directive "server" in /etc/nginx/sites-enabled/default:1
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)

我尝试查看以下问题: nginx: [emerg] "http" 指令不允许在 /etc/nginx/sites-enabled/default:1

nginx: [emerg] 未知指令 " " in /etc/ nginx/sites-enabled/example.com:3

我的默认配置如下所示:

server {
 listen 80;
 location / {
 proxy_pass http://localhost:5000;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection keep-alive;
 proxy_set_header Host $host;
 proxy_cache_bypass $http_upgrade;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 }
}
Run Code Online (Sandbox Code Playgroud)

安装 Nginx 并转到端口 80 上的默认 Nginx 服务器工作正常。但是当我开始上传自己的配置并进行更改时,它就崩溃了。

脚步:

sudo chown ubuntu:ubuntu /etc/nginx/sites-available/default
Run Code Online (Sandbox Code Playgroud)

所以我可以使用 SCP 上传新的默认站点

scp -o StrictHostKeyChecking=no -i {pemFile} -qrp C:/path/. ubuntu@{hostname}:/etc/nginx/sites-available/
Run Code Online (Sandbox Code Playgroud)

https://garywoodfine.com/deploying-net-core-application-to-aws-lightsail/https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.0看起来非常相似,但没有任何结果。

vit*_*ira 6

我遇到了同样的问题,我通过使用 Notepad++ 打开 nginx.conf 并将其转换为 ANSI 来修复

格式 > 转换为 ANSI