【问题标题】:nginx: [emerg] unknown directive "server" in /etc/nginx/sites-enabled/default:1nginx:[emerg] 未知指令“服务器”在 /etc/nginx/sites-enabled/default:1
【发布时间】: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


【解决方案1】:

我有同样的问题,我通过使用 Notepad++ 打开 nginx.conf 并将其转换为 ANSI 来解决

格式 > 转换为 ANSI

【讨论】:

    【解决方案2】:

    我也遇到过同样的问题。后来,我使用 Filezila 上传了配置文件,并且成功了。

    【讨论】:

      【解决方案3】:

      嗯。在让这个问题出现在 Stackoverflow 上一段时间后,我尝试在我的计算机上启动虚拟机。创建一个内容完全相同的配置文件。将粘贴从我的 Windows 机器复制到我的 linux 机器。将文件上传到我的 linux 服务器,它可以工作。

      所以简而言之,Windows 搞砸了文件的内容,而我什么都看不到。我在这里上传了文件的工作版本: https://s3-eu-west-1.amazonaws.com/topswagcode.dev/default

      【讨论】:

        猜你喜欢
        • 2013-10-10
        • 1970-01-01
        • 2021-06-26
        • 1970-01-01
        • 1970-01-01
        • 2021-08-30
        • 2016-01-05
        • 2015-11-22
        • 2017-11-10
        相关资源
        最近更新 更多