Question

Exclude specific sub-domains from server where have wildcard server name

Hi, is it possible to have 3 server blocks with following server name? server block 1

server_name example.com www.example.com;

server block 2

server_name demo.example.com;

server block 3

server_name *.example.com;

reason i want to have like this, my main site will have server block 1, a demo will have server block 2, server block 3 will maintain the configuration for all other sub-domains that my client will create from my application.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Yes, Nginx uses the wildcard on anything not specified. http://nginx.org/en/docs/http/server_names.html

@newbie

That’s definitely possible :-). Just make sure you have an A entry for the WildCard in your DNS Zone otherwise it won’t work properly.

For example:

A          @          DROPLET_IP
A          *          DROPLET_IP
A          www        DROPLET_IP
A          demo       DROPLET_IP

Alternatively, you can use a CNAME for www:

A          @          DROPLET_IP
A          *          DROPLET_IP
CNAME      www        example.com
A          demo       DROPLET_IP

Though for completeness, I’d recommend:

A          @          DROPLET_IP
A          *          DROPLET_IP
A          www        DROPLET_IP
A          demo       DROPLET_IP
A          www.demo   DROPLET_IP

or

A          @          DROPLET_IP
A          *          DROPLET_IP
CNAME      www        example.com
A          demo       DROPLET_IP
CNAME      www.demo   demo.example.com

… and changing:

server_name demo.example.com;

to

server_name demo.example.com www.demo.example.com;