Im no expert on nginx but i got my problem solved by doing this:
server_name ~^(?<vhost>.*)$;
root /var/www/$vhost/public;
For example if a user types in a web browser http://sysadmin.mydomain.com nginx will use the doc root of /var/www/sysadmin.mydomain.com/public
And this works fine, but in doing so I have created another problem with PHP $_SERVER['SERVER_NAME']; and its that this will print: ~^(?.*)$ causing problems somewhere else in my code.
My solution works for nginx but its not the right solution. How can i achieve this and still retain a 'readable' server name?
This does the trick for what I want:
server_name mydomain.com ~^(?<vhost>.+)\.mydomain\.com$;
root /var/www/$vhost.mydomain.com/public;
$_SERVER['SERVER_NAME'] will answer: mydomain.com and thats fine for what I want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With