【发布时间】:2019-02-21 14:46:34
【问题描述】:
我启动了自己的 VPS,并使用 NGINX 启动了一个 Web 服务器。我有一个 index.html。如何创建其他页面,例如关于页面,并将其放在 www.my-domain-name.com/about/
这是否意味着我必须编辑我的 app.js 文件,如果是,如何编辑?
修正:我在 Express 代码中添加了 Lazar 建议的修正以获取 about.html。
'use strict';
const express = require("express");
const app = express();
// Static css/js files
app.use('/static', express.static('./dist'));
app.get("/", function(req, res) {
res.sendFile( __dirname + '/index.html');
});
app.get("/about", function(req, res) {
res.sendFile( __dirname + '/about.html');
});
const port = 3001;
// Start server
app.listen(port, function() {
console.log("Listening on " + port);
});
在index.html中,about页面的链接是:
<a href="/about.html">About me.</a>
/about 和 /about.html 目前都不起作用并收到错误消息:Cannot GET /about.html
编辑:我使用的是forever,所以我必须forever restartall
【问题讨论】:
标签: html express nginx forever