Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 :)

like image 212
Rafael Barón Castro Avatar asked May 10 '16 02:05

Rafael Barón Castro


4 Answers

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.

like image 197
jningthou Avatar answered Oct 31 '22 19:10

jningthou


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.

like image 37
Robert Seaman Avatar answered Oct 31 '22 18:10

Robert Seaman


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

    }
}
like image 6
manoj prashant k Avatar answered Oct 31 '22 17:10

manoj prashant k


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.

like image 2
Thanh Nguyen Van Avatar answered Oct 31 '22 17:10

Thanh Nguyen Van