nginx -t command?http {
server {
listen 80;
location / {
root /var/www/html;
}
}
location /images/ {
root /var/www/images;
}
}location blocks are allowed inside nginx configuration.The location directive must be inside a server block. Here, the location /images/ block is placed directly inside the http block, which is invalid. This causes an error when testing the configuration.
server block and not directly inside the http block?The listen directive specifies the IP and port for a server to accept connections and must be inside a server block. The others are valid in the http or main context.
server {
listen 443 ssl;
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
server_name example.com;
http {
location / {
proxy_pass http://localhost:3000;
}
}
}The http block is a top-level block and cannot be placed inside a server block. Nesting it inside causes a configuration error.
The http block is the top-level block for HTTP settings. Inside it, you place server blocks. Inside server, you place location blocks.
Using multiple server blocks inside http and splitting configuration into separate files included with include directives helps keep configuration organized and easier to maintain.