I've just installed Nginx on my server and am extremely happy with the results, however I still cannot figure out how to insert wildcard virtual hosts.
This is the [directory] structure I'd like:
-- public_html (example.com)
---subdoamin 1 (x.example.com)
---subdomain 2 (y.example.com)
As you can see it's pretty basic, however, I'd like the ability to add domains by simply adding an A record for a new subdomain, which will instantly point to the subdirectory of the same name under public_html.
There's stuff on the web, however I haven't come across something exactly like this.
Any help would be greatly appreciated.
I shall show you.
The configuration file
Test files
We have two test files:
Testing
Static server names:
And regexp server name:
This Nginx configuration file below allows for wildcard hostnames that dynamically route to the corresponding folder in
/var/www/vhost/
while also dynamically generating the respective log files.http://test1.wildcard.com
→/var/www/vhost/test1
/var/log/nginx/test1.wildcard.com-access.log
/var/log/nginx/test1.wildcard.com-error.log
http://test2.wildcard.com
→/var/www/vhost/test2
/var/log/nginx/test2.wildcard.com-access.log
/var/log/nginx/test2.wildcard.com-error.log
wildcard.conf
This is how I've handled Virtual Hosts with Nginx:
I'm not sure why Wildcard Subdomains in a Parent Folder is so wrong/misleading.