# Nginx catching all domains without wildcard

**URL:** <https://www.ruby-forum.com/t/nginx-catching-all-domains-without-wildcard/243730>\
**Category:** NGINX\
**Created:** [December 28, 2015, 3:53am UTC](https://www.ruby-forum.com/t/nginx-catching-all-domains-without-wildcard/243730 "2015-12-28T03:53:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 28, 2015, 3:53am UTC](https://www.ruby-forum.com/t/nginx-catching-all-domains-without-wildcard/243730/1 "2015-12-28T03:53:28Z")

</div>

My Nginx config is catching all subdomains without specifying a  
wildcard. I  
have created an special config for each subdomain, but seems that all  
subdomains pass trough the main domain configuration. I have discovered  
this by removing the subdomains configuration files from nginx.conf and  
watching how it still catches all the subdomains, so when I send a  
request  
to [uk.domain.com](http://uk.domain.com), instead of Nginx catching the subdomain configuration,  
goes through the main domain configuration. This is causing trouble with  
applying mod\_pagespeed individually to each of the sites and also  
managing  
the GA universal code.  
The config for the main domain is this :

> **[server { listen 80; server\_name www.domain.com; return 301 $schem -...](https://pastebin.com/4AvGgRCc)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

http config :

> **[user www-data;worker\_processes 2;#error\_log /var/log/nginx/logs/error -...](https://pastebin.com/CkJLHyHH)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

If I haven’t setup a wildcard, how come the main domain config is  
catching  
all subdomains ??

Thanks

---

<div class="post-metadata">

**Author:** ![Xavier\_Cardil\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/9dc877/32.png) [@Xavier\_Cardil\_C](https://www.ruby-forum.com/u/Xavier_Cardil_C)\
**Post date:** [December 28, 2015, 1:42pm UTC](https://www.ruby-forum.com/t/nginx-catching-all-domains-without-wildcard/243730/2 "2015-12-28T13:42:19Z")

</div>

In the configuration you provided, there are 3 server blocks:

- 80 [www.domain.com](http://www.domain.com)
- 443 (default server) [domain.com](http://domain.com)
- 127.0.0.1:8081 [elsitar.com](http://elsitar.com)

There is no server block defined for [uk.domain.com](http://uk.domain.com) (you main config file  
has an include directive for a /etc/nginx/uk.domain.com file which is  
commented though), thus a default server block will be selected.

On port 443, for all IP addresses, the [domain.com](http://domain.com) server block will be  
chosen as it is defined as being the default.  
On port 80, there is no default port defined, thus the first (and only)  
one  
will be used.  
On 8081 for the localhost IP address 127.0.0.1, as for 80, there is no  
default port so the first (and only) server block defined for the  
IP:port  
pair will be selected as the default.

## There is no magical behavior, please make sure you understand the docs. There is even a webpage dedicated to server names: [Server names](http://nginx.org/en/docs/http/server_names.html)

_B. R._

On Mon, Dec 28, 2015 at 3:52 AM, Xavier Cardil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
