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

7

21

I'm new at nginx and Raspberry.

I installed nginx using

sudo apt-get install

And everything was fine at that point. The problem came when I tried to restart nginx, It threw this error

Job for nginx.service failed. See 'systemctl status ngins.service' and 'journaldtl -xn' for details

After an investigation I found that the problem is the next error:

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

My default file is:

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
## 

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 /

I hope you can help me :)

Doak answered 10/5, 2016 at 2:20 Comment(2)
can you show the 20th line in default file ?Demakis
Is exactly the line below :location / I tried writing ´}´ but it doesn't work. In fact I didn't modify that file :/Ardene
S
26

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.

For example line like this will give error,

server_name localhost

Adding ';' to end like this will fix it

server_name localhost;
Statistics answered 30/7, 2018 at 6:21 Comment(1)
Thanks.I just missed a “;” at the end of a new added line inside the location block {}.Laparotomy
N
17

My issue was due to missing a ; as part of one of the command line arguments.

For reference here are my logs:

2020/08/11 17:19:25 [emerg] 1#1: unexpected end of parameter, expecting ";" in command line
nginx: [emerg] unexpected end of parameter, expecting ";" in command line

My mistake was I started nginx with the following CMD via docker:

CMD ["nginx", "-g", "daemon off"]

Where I was missing the trailing ;. What I should have had was:

CMD ["nginx", "-g", "daemon off;"]

Just in case it helps anybody else out.

Noyade answered 11/8, 2020 at 17:32 Comment(2)
Gah, so easy to miss. I'm pouring over my config and could not find it. This was exactly it.Tiana
I was losing my mind! Thank youSouthsouthwest
C
6

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 / {

    }
}
Comedian answered 10/5, 2016 at 5:8 Comment(0)
Y
3

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;
}
Yah answered 22/8, 2019 at 12:8 Comment(0)
D
2

Correct your nginx file as below :

For example:

http {


       upstream api-app {
        .....................;   

        }
        ........................; 
        server {

              location / {
               ...................;
               proxy_set_header Host $host;
               proxy_cache_bypass $http_upgrade;

              }
        }

}

Make sure ; at the end of line, and { ..} correctly.

Demakis answered 10/5, 2016 at 4:41 Comment(0)
P
0

For me I forgot to put server before the {

Poorhouse answered 16/2, 2022 at 19:0 Comment(0)
C
0

Just posting my issue as well.

My dockerfile includes envsubst so I needed to use alt character for '$' to be preserved.

Docker CMD: CMD envsubst < /etc/nginx/nginx.conf | sed -e 's/§/$/g' > /etc/nginx/nginx.conf && nginx -g 'daemon off;'

Set proxy host: proxy_set_header Host §http_host;

Cacuminal answered 7/9, 2022 at 9:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.