【发布时间】:2020-02-17 21:48:01
【问题描述】:
我正在尝试将 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
我已尝试查看以下问题:
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:1
和
nginx: [emerg] unknown directive " " 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;
}
}
安装 Nginx 并转到端口 80 上的默认 Nginx 服务器工作正常。但是当我开始上传自己的配置并进行更改时,它会中断。
步骤:
sudo chown ubuntu:ubuntu /etc/nginx/sites-available/default
所以我可以使用 SCP 上传新的默认站点
scp -o StrictHostKeyChecking=no -i {pemFile} -qrp C:/path/. ubuntu@{hostname}:/etc/nginx/sites-available/
https://garywoodfine.com/deploying-net-core-application-to-aws-lightsail/ 和 https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.0 看起来非常相似,但没有任何结果。
【问题讨论】:
-
要了解原因,您需要查看文件包含在整体配置中的位置。可能之前包含的文件中缺少关闭
}使得server指令似乎嵌套在错误的块中。使用nginx -T(大写T)查看所有包含文件的完整配置。 -
ubuntu@ip-172-26-12-97:~$ sudo nginx -T nginx: [emerg] 未知指令 "server" 在 /etc/nginx/sites-enabled/default:1 nginx : 配置文件 /etc/nginx/nginx.conf 测试失败了就是我得到的。
标签: nginx asp.net-core