[英]How to correctly serve a static site on NGINX with node-restify?
I'm having some issues with this, wondering if anyone had any insights. 我对此有一些疑问,想知道是否有人有任何见解。
I have a public
controller 我有一个public
控制者
import restify from ‘restify’;
const { serveStatic } = restify.plugins;
const directory = __dirname + ‘/../../../public’;
const serveSite = () => serveStatic({ directory, default: ‘index.html’ });
const serveFile = file => serveStatic({ directory, file });
export default server => {
server.get(‘/*’, serveSite());
server.get(‘/about’, serveFile(‘about.html’));
};
My static site (which is built using nextjs
) is built and stored in /public
on the server, remotely. 我的静态站点(使用nextjs
)是远程构建并存储在服务器上的/public
。 My NGINX location directive looks like this 我的NGINX位置指令如下所示
location / {
try_files $uri $uri/ =404;
}
Going to /
and reloading serves the site correctly. 转到/
然后重新加载即可正确访问该网站。 Navigating to /about
via the nav works fine, but if I refresh this route, I get a 404 page from NGINX. 通过导航导航到/about
可以正常工作,但是如果刷新此路线,则会从NGINX获取404页面。 If I go to /about.html
it works. 如果我转到/about.html
它将起作用。 Locally, just testing restify without NGINX involved, everything works fine so I feel it must be something to do with the server config. 在本地,仅在不涉及NGINX的情况下进行再验证就可以了,一切工作正常,因此我认为这必须与服务器配置有关。
Answering my own question, the location directive needs an extra option 在回答我自己的问题时,location指令需要一个额外的选择
location / {
try_files $uri $uri/ $uri.html =404;
}
And everything works. 一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.