How to Fix "unexpected end of file" nginx error

Endrit Qerreti

Endrit Qerreti

I tried restarting my nginx server today, and got the following error:

nginx: [emerg] unexpected end of file, expecting "}" in /etc/nginx/sites-enabled/

This error means the nginx configuration file has not been configured correctly, or it was configured correctly but you forgot to close the directives with curly braces {} or semicolon ;

And because of this error nginx won't be able to start or restart.

However, this error can be solved easily, by following our steps below.

Step 1 - Open Nginx Configuration File

The error is being caused on the virtual block that we had created which is located /etc/nginx/sites-enabled/, so you need to open the config file with your favorite text editor

sudo nano /etc/nginx/sites-enabled/

Now once you have opened the virtual block with the text editor you need to make sure there's no { or ; missing on any parameters on the config file.

See the example config below, this is how a normal virtual block configuration looks like, this config has two open "{" and two "}" to close the block.

server {
        listen 80;
        listen [::]:80;

        root /var/www/;
        index index.html index.htm index.nginx-debian.html;


        location / {
                try_files $uri $uri/ =404;


Step 2 - Restart Nginx

Once you have inspected the configuration file and added the missing curly braces or ; now you should run the command to make sure the nginx syntax has been configured correctly.

sudo nginx -t 

Once you enter the command above, it should tell you if the test was successful or not, proceed with restart if test was successful

sudo systemctl restart nginx

Step 3 - Delete old .save config files

if nginx won't start even after configuring it correctly, make sure to check there's no files like : / located on


To see if those files are created there, navigate to the path and type ls command to list all files inside enabled sites directory

#Go to the path
cd /etc/nginx/sites-enabled

#List all files inside the directory

If you see these files then you need to delete them, to delete them simply type the command below

sudo rm /etc/nginx/sites-enabled/*.save

The wildcard command will remove all files that end with .save extension

You can also delete them manually without using the wildcard by using the command below

sudo rm /etc/nginx/sites-enabled/

Another way of deleting them is to go to the directory where the .save files are and just delete them

For example : To go to the directory /etc/nginx/sites-enabled type

cd /etc/nginx/sites-enabled

and then simply delete the file with the .save extension

sudo rm

Once you have deleted the .save files, try to run this command again to check nginx syntax

sudo nginx -t

If not errors came up, then simply restart nginx and your site should be running correctly

sudo systemctl restart nginx


In this tutorial you learned how to fix the error "nginx: [emerg] unexpected end of file, expecting "}" in /etc/nginx/sites-enabled.