Nginx访问html资源(带或不带扩展名)

Nginx访问html资源(带或不带扩展名),html,nginx,Html,Nginx,我想访问带有或不带扩展名的HTML资源。目前,我定义了两个位置块,如下所示 location = /home { default_type "text/html"; alias /var/www/html/home.html; } location = /home.html { default_type "text/html"; alias /var/www/html/home.html; } 如何在单个位置块中写入上述配置?您可

我想访问带有或不带扩展名的HTML资源。目前,我定义了两个位置块,如下所示

location = /home {
        default_type "text/html";
        alias /var/www/html/home.html;
}
location = /home.html {
        default_type "text/html";
        alias /var/www/html/home.html;
}

如何在单个位置块中写入上述配置?

您可以使用
try\u files
测试各种文件名匹配,例如:

root /var/www/html;

location / {
    try_files $uri $uri.html $uri/ =404;
}
有关详细信息,请参阅