如何使用Nginx将Angular8 SSR部署到Ec2?

时间:2019-11-05 12:47:31

标签: angular amazon-web-services universal

我创建了angular8应用,对于SEO,我使用了angular Universal,它在localhost上运行良好,但是每当在ec2上部署时都无法正常工作

我用过

  

ng添加@ nguniversal / express-engine --clientProject angular-universal-app

此操作可创建适用于http://localhost:4000的SEO友好版本,但是每当我部署Live时,它都无法正常工作

这是我的服务器文件

import 'zone.js/dist/zone-node';

import * as express from 'express';
import {join} from 'path';
const app = express();
const PORT = process.env.PORT || 443;
const DIST_FOLDER = join(process.cwd(), 'dist/browser');
const {AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap} = require('./dist/server/main');


app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));
app.set('view engine', 'html');
app.set('views', DIST_FOLDER);
app.get('*.*', express.static(DIST_FOLDER, {
  maxAge: '1y'
}));
app.get('*', (req, res) => {
  res.render('index', { req });
});
app.listen(PORT, () => {
  console.log(`Node Express server listening on http://localhost:${PORT}`);
});

想要在线搜索引擎优化

0 个答案:

没有答案