PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 20, 2022

[FIXED] Why does example.com behave exactly as .example.com?

 September 20, 2022     nginx, virtualhost     No comments   

Issue

I don't know why server_name example.com matches also subdomains (at least when there's not a rule for those), if there's an specific syntax for doing so:

Nginx documentation states that you can define server_name in the following ways:

Sets names of a virtual server, for example:

server_name example.com;

Server names can include an asterisk (“*”) replacing the first or last part of a name:

server_name *.example.com;

Such names are called wildcard names.

The first two of the names mentioned above can be combined in one:

server_name .example.com;

But I tested this, and example.com behaves just as .example.com is expected, matching also all the subdomains.

This is not a problem as I can override the subdomains by setting a server for *.example.com but it seems very odd to me that if the syntax of .example.com exists with the intention to match both other two, it should mean that the other two don't match to eachother...

Why is this?


Solution

If your subdomains don't match any rule, they will be called back to the rule tagged as default_server, which, by default, is the first one on the file. In this case, the example.com rule.

This is the answer to the right question:

https://stackoverflow.com/a/64742545/8719655



Answered By - Carlos López Marí
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing