Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

packy's avatar
Level 7

Add Wildcard Subdomains to existing sites

How do I add Wildcard Subdomains to a site I already created? Do I have to edit the NGINX Config file?

I saw placing this in the server{} section: server_name ~^(.*)\.example\.com$ ; but wasnt sure. I have always used .htaccess so I am not too familiar with NGINX

0 likes
1 reply
packy's avatar
packy
OP
Best Answer
Level 7

Okay for it to work you need to do 2 things:

First, set up your A record on your DNS so its host is * and it points to your server IP

Then, in your NGINX config file for the site you just need to change:

server_name mydomain.com;

to

server_name .mydomain.com;

Notice the . before the domain name. It should then work (might take a little time for the DNS to recognize it, but worked).

Please or to participate in this conversation.