根据Nginx wiki,该$hostname
变量设置为 gethostname 返回的机器主机名。
我试过了,虽然gethostname
我的 Debian 盒子不起作用,但它仍然正确地返回主机。然后我尝试使用该变量$hostname
来设置server_name
,但这不起作用。
为什么会这样,还有其他方法可以实现吗?
server {
listen 80;
autoindex off;
server_name static.$hostname;
root /var/www/static;
access_log /var/log/nginx/localhost.access.log;
location / {
index index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
Run Code Online (Sandbox Code Playgroud)