nginx unexpected end of file, expecting ";" or "}" in /etc/nginx/sites-enabled/default:20 over Raspbian

I had the same issue. Confirmed there was a missing ; at the end of a new added line inside the server block {...} .

Ensure the curly braces and ; are all in place.


as @Thanh Nguyen Van has answered already. the location has to be opened and closed in curly braces and then another curly brace for your server's end

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    listen 80;
    server_name $domain_name;
    root /var/www;
    index index.html index.htm;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {

    }
}

Also make sure you have no unexpected quotes (single nor double). It took me a while to figure out one time when I was using Docker and passing the value as an env var, so it was mistakenly quoted.

So, this will be an incorrect bit:

upstream backend {
    "server localhost:9000;"
}

This is a correct one:

upstream backend {
    server localhost:9000;
}