Wrong site()->url with three subdomains

Hi everybody!

On our dev server we use mutiple subdomains:
so it is project.developer_name.fqdn.ending

Right now I have kirby.malte.dev.example.com and using the Kirby Starterkit the assets can’t be loaded.
Using the console / site() object I can see, that Kirby is ignoring the first part of the subdomain:

 (
    [title] => Kirby Starterkit
    [url] => http://..malte.dev.example.com
    [page] => home
    [content] => Content Object
    (..)

Thanks for your help!

These three lines of code are responsible for detecting the base URL behind the scenes.

Kirby uses the values that are set by the web server using server environment variables. I don’t see any operation that could be causing this directly.

Could you please check what is inside your $_SERVER object?
In the meantime, you can also set the url option to the full URL manually:

c::set('url', 'http://kirby.malte.dev.example.com');

I am sorry, my first post was send to early by my mistake and then flagged as spam :frowning:

Thanks for your reply!
$_SERVER shows:

Array
(
    [USER] => www-data
    [HOME] => /var/www
    [FCGI_ROLE] => RESPONDER
    [APPLICATION_ENV] => development
    [QUERY_STRING] => 
    [REQUEST_METHOD] => GET
    [CONTENT_TYPE] => 
    [CONTENT_LENGTH] => 
    [SCRIPT_FILENAME] => /home/malte/www/example/docs/index.php
    [SCRIPT_NAME] => /index.php
    [REQUEST_URI] => /
    [DOCUMENT_URI] => /index.php
    [DOCUMENT_ROOT] => /home/malte/www/example/docs
    [SERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_SOFTWARE] => nginx/1.2.1
    [REMOTE_ADDR] => 192.168.15.6
    [REMOTE_PORT] => 62690
    [SERVER_ADDR] => 192.168.0.120
    [SERVER_PORT] => 80
    [SERVER_NAME] => ~^(?.+)\.malte\.dev\.example\.com$
    [HTTPS] => 
    [REDIRECT_STATUS] => 200
    [HTTP_HOST] => example.malte.dev.example.com
    [HTTP_CONNECTION] => keep-alive
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
    [HTTP_ACCEPT_LANGUAGE] => en,de;q=0.8,en-US;q=0.6
    [HTTP_COOKIE] => _ga=GA1.2.753372557.1480972576
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1491336930.016
    [REQUEST_TIME] => 1491336930
)

Setting it manually (I think it is meant to go int /site/config/config.php?) doesn’t change anything, the assets still can’t be loaded :confused:

Thanks so much for your help!

Best
Malte

ps: if it helps - seeing that $_SERVER['SERVER_NAME'] is set wrong - I am running nginx with wildcard subdomains; every folder in /home/malte/__project__/docs automatically gets a vhost for __project__.dev.example.com

new observation: it seems that nginx is the problem - running apache and three subdomains seem to be working fine…

Hm, in your nginx result posted above, SERVER_NAME is set to the regex that is used to match the subdomains. Of course that can’t work as Kirby expects the current host name there.

It looks like this is just the way nginx sets environment variables. HTTP_HOST would be correct here.
Kirby isn’t officially compatible with nginx, but this still looks like a bug.

If anyone knows a robust and reliable way to detect the host that is compatible with all common web servers, please send a PR to the Toolkit repo.