nginxasp.net-core

nginx: [emerg] unknown directive "server" in /etc/nginx/sites-enabled/default:1


I am trying to setup Nginx to my ASPNET Core WebApi. But I keep running into errors.

When I try to check my Config I get:

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

I have tried to look at the following issues: nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:1
and
nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3

my default config looks like the following:

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;
 }
}

Installing Nginx and going to default Nginx server on port 80 works fine. But when I start to upload my own configs and make changes it breaks.

Steps:

sudo chown ubuntu:ubuntu /etc/nginx/sites-available/default

so I can use SCP to upload new default site

scp -o StrictHostKeyChecking=no -i {pemFile} -qrp C:/path/. ubuntu@{hostname}:/etc/nginx/sites-available/

Both https://garywoodfine.com/deploying-net-core-application-to-aws-lightsail/ and https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.0 seems pretty similar without any results.


Solution

  • I had the same issue, i fixed by opening the nginx.conf with Notepad++ and convert it to ANSI

    Format > Convert to ANSI