【发布时间】:2023-01-14 05:43:50
【问题描述】:
我将 next.js 导出到 out 文件夹中。
文件夹结构为:
- 出来
- index.html
- 条款.html
- privacy.html
我将 nginx 设置为从该文件夹提供文件:
server {
root /var/www/myproject/out;
index index.html index.htm index.nginx-debian.html;
server_name myproject.com;
location / {
try_files $uri $uri/ /index.html;
}
}
主页(索引)打开正常。从应用程序内导航到 myproject.com/privacy 之类的网址可以正常工作。问题是如果我尝试直接打开这些链接,它将提供主页(索引)而不是实际页面,因为文件夹中不存在这些 url。直接打开隐私页面的唯一方法是在 url 中添加 html 扩展名:myproject.com/privacy.html。
当有人输入 myproject.com/privacy url 时,如何配置 nginx 为实际页面 myproject.com/privacy.html 提供服务?
【问题讨论】:
-
在 try_files 中包含 $uri.html
-
@Nayan 保佑你,我的朋友,它按预期工作。您想创建一个正确的答案以便我接受吗?
-
当然。添加了答案。