I was looking at my nginx config file I noticed two this.
server { listen 80 default_server; listen [::]:80 default_server; index index.html; }
I understand this part listen 80 default_server;
it tells nginx to listen on port 80 and set that as the "default_server" but I do not understand the second line.
listen [::]:80 default_server;
It appears I am setting the default server again on port 80 but I do not really understand the [::]
part of it at all.
Can someone explain to me what this configuration does?
If the server name is not found, the request will be processed by the default server. For example, a request for www.example.com received on the 192.168. 1.1:80 port will be handled by the default server of the 192.168. 1.1:80 port, i.e., by the first server, since there is no www.example.com defined for this port.
Through a simple command you can verify the status of the Nginx configuration file: $ sudo systemctl config nginx The output will show if the configuration file is correct or, if it is not, it will show the file and the line where the problem is.
By default, the configuration file is named nginx. conf and placed in the directory /usr/local/nginx/conf , /etc/nginx , or /usr/local/etc/nginx .
Understanding Nginx Configuration Contexts. This guide will cover the basic structure found in the main Nginx configuration file. The location of this file will vary depending on how you installed the software on your machine. For many distributions, the file will be located at /etc/nginx/nginx.conf.
What are Location Blocks? Every NGINX configuration file will be found in the /etc/nginx/ directory, with the main configuration file located in /etc/nginx/nginx.conf . NGINX configuration options are known as “directives”: these are arranged into groups, known interchangeably as blocks or contexts .
If you’re making changes to your nginx configuration files, you are running a huge risk if you restart nginx and you made a mistake, a typo, or copied and pasted from Stackoverflow wrong. Luckily there’s an easy built-in way to test your configuration files to make sure they won’t break everything.
These are the contexts that comprise the major structure of an Nginx configuration. The most general context is the “main” or “global” context. It is the only context that is not contained within the typical context blocks that look like this:
It is for the IPv6 configs
from the nginx docs
IPv6 addresses (0.7.36) are specified in square brackets: listen [::]:8000; listen [::1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With