Welcome! Log In Create A New Profile

Advanced

Default Server Block

W. Andrew Loe III
May 06, 2010 01:22PM
The wiki says:

"If the directive has the default parameter, then the enclosing server
{...} block will be the default server for the address:port pair. This
is useful for name-based virtual hosting where you wish to specify the
default server block for hostnames that do not match any server_name
directives. If there are no directives with the default parameter,
then the default server will be the first server block in which the
address:port pair appears."

I have multiple server blocks listening on both 80 and 443:

server {
listen 80;
server_name mydomain.com;
...
}

server {
listen 443;
server_name mydomain.com;

ssl on;
ssl_certificate certs/mydomain.crt;
ssl_certificate_key certs/mydomain.key;

...
}

server {
listen 80;
server_name myotherdomain.com;
...
}

server {
listen 443;
server_name myotherdomain.com;

ssl on;
ssl_certificate certs/myotherdomain.crt;
ssl_certificate_key certs/myotherdomain.key;

...
}

Does this mean if a request with either an unmatched Host header or no
Host header, will go to port 80 for mydomain.com because it is the
first block, or will this request get dropped because it does not
match any server_name directives?

If it is being served by the first block, would I catch this with a
server_name of "" and a default directive?

# Catch-all, redirect somewhere useful.
server {
listen 80 default;
server_name "";

# Do something useful with this traffic;
}

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Default Server Block

W. Andrew Loe III May 06, 2010 01:22PM

Re: Default Server Block

Igor Sysoev May 06, 2010 01:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 164
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready