0

我可以将我的 Angular 5 网站托管给任何网络托管服务提供商吗?

如果我执行“ng build --prod”,我可以将 dist 文件夹中的所有内容部署到托管服务提供商吗?还是角度要求您找到特定的网络托管服务?

我试图使用 Namecheap 托管或 000webhosting,但我想确保它有效。

4

2 回答 2

2

是的!。考虑创建的dist/文件夹是包含 index.html 的静态文件夹。

您可以使用任何网络托管服务来提供dist 文件夹中的index.html

我正在使用 nodejs 为dist/文件夹提供服务。如果您想执行以下步骤。

在根级别创建app.js文件并复制以下代码;

const express = require('express'),
http    = require('http'),
path    = require('path');

const app = express();

app.use(express.static(path.join(__dirname, 'dist')));

app.get('*', (req,res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
})

const port = process.env.PORT || '4201';
app.set('port', port);

const server = http.createServer(app);
server.listen(port,() => console.log('Running at port '+port))

然后安装快递

npm install --save express

确保您已构建

现在做node app.js

如果您在 AWS Web 服务中也有同样的需求

将您的 dist 发送到 aws 服务器 ec2 实例

安装pm2

现在pm2 start app.js

恭喜您在 aws 中托管了您的应用程序。

于 2018-03-08T04:34:06.980 回答
2

您还可以在 Apache 服务器上托管构建文件。我只是将它们复制到 htdocs 目录,它对我有用。

于 2018-03-08T04:51:54.010 回答