nginx: is there a fqdn version of $hostname?

I'm trying to get nginx to match my host's full name (including domain name). as far as i can tell $hostname only includes the hostname, not the domain, so it's useless for this.

$ hostname -f
www.example.com

things i have tried:

server_name www.example.com          # works
server_name $hostname                # fails, only matches 'www'
server_name $hostname.example.com    # fails, doesn't match anything
server_name "$hostname.example.com"  # ditto
server_name ${hostname}.example.com  # ditto
server_name $(hostname).example.com  # ditto

beyond hard-coding my hostname into my nginx.conf file (which I need to avoid), what are my options here?


As a workaround, you can add the following line to your nginx startup script:

echo -e "server_name `hostname -f`;\n" > /etc/nginx/hostname.conf

and then use the include hostname.conf; directive in your nginx config file.