如何在Nginx中为根url提供特定文件?
我需要为如何在Nginx中为根url提供特定文件?,nginx,Nginx,我需要为GET/请求提供文件系统中的文件。我尝试了以下方法: location = / { index page2257160.html; root /var/www/site/; } 其余请求将代理到后端: location / { proxy_pass http://localhost:1234; } 但当我执行请求时,nginx不是从文件系统提供文件,而是向后端询问/page2257160.html,后端返回404,nginx将此404发送回客户端 如何修复此问题?指令执行
GET/
请求提供文件系统中的文件。我尝试了以下方法:
location = / {
index page2257160.html;
root /var/www/site/;
}
其余请求将代理到后端:
location / {
proxy_pass http://localhost:1234;
}
但当我执行请求时,nginx不是从文件系统提供文件,而是向后端询问/page2257160.html
,后端返回404,nginx将此404发送回客户端
如何修复此问题?指令执行内部重定向,因此需要第二个位置来匹配重写的URI。例如:
root /var/www/site/;
location = / {
index page2257160.html;
}
location = /page2257160.html {
}
location = / {
root /var/www/site/;
try_files /page2257160.html =404;
}
有关详细信息,请参阅
您可以使用一个
位置
块和一个try\u files
指令实现相同的功能。例如:
root /var/www/site/;
location = / {
index page2257160.html;
}
location = /page2257160.html {
}
location = / {
root /var/www/site/;
try_files /page2257160.html =404;
}
更多信息,请参阅