Nginx: unknown directive “server_name”

nginx

My nginx server (from docker image: nginx:stable-alpine) won't start. When I check the logs I see this error:

[emerg] 1#1: unknown directive "server_name:" in /etc/nginx/conf.d/default.conf:4

Here is my config file:

server {
    listen 80;
    index index.php index.html;
    server_name: localhost;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

I tried searching fot his error and read something about it supposed to be in an http block so when I tried adding

http {

at the begining and

} 

at the end I get a different error

[emerg] 1#1: "http" directive is not allowed here in
/etc/nginx/conf.d/default.conf:1

So I'm not sure what else to try.

Best Answer

There is no server_name: in NGINX, indeed.

There is server_name. You should not include colon :, then it will work.