Server

Contents

Server#

This section discusses features of the nginx virtual servers that are defined by the server directive. Check details in the corresponding section of the official documentation.

docker run -itd --name experiment_nginx --rm -p 80:80 nginx

Note: Don’t forget to stop the example nginx when you are done interacting with it.

docker stop experiment_nginx
experiment_nginx

Duplicate name#

You can’t specify the same name for two servers. In such a case, nginx would throw a corresponding error when trying to apply the config.


The following example shows a special case of the duplicate server name - empty names for both servers.

docker exec -i experiment_nginx sh -c 'cat >  /etc/nginx/nginx.conf' <<EOF
events {}
http {
    server {return 200 "first";}
    server {return 200 "second";}
}
EOF
docker exec experiment_nginx nginx -s reload
2024/12/26 11:51:34 [warn] 124#124: conflicting server name "" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored
2024/12/26 11:51:34 [notice] 124#124: signal process started

As a result, we got corresponding errors during server deployment. In general, nginx started, but virtual servers with duplicate names were ignored.